Xcode 7: `auto` does not preserve Objective–C++ generics when indirected

Originator:daniel
Number:rdar://21765641 Date Originated:2015-07-10
Status:Duplicate of 21343421 (Open) Resolved:2015-07-13
Product:Developer Tools Product Version:7.0 beta 3 (7A152u)
Classification:Other Bug Reproducible:Always
 
Summary:
In Objective–C++ code, using the `auto` keyword correctly preserves type annotations for e.g. NSArray return values, such as the following:

    // given that view is some UIView *:
    auto const interestingViews = view.subviews;
    // interestingViews is of type NSArray<__kindof UIView *> *const -- as expected

If, however, those values are indirected through other generic class methods, the type annotations are lost:

    // again we have some UIView *view:
    auto const viewsToFilter = [NSMutableArray arrayWithArray:view.subviews];
    // type information is lost: viewsToFilter is of type NSMutableArray *const
    // even though arrayWithArray: is annotated with ObjectType
    // i.e. it _should_ produce NSMutableArray<ObjectType> *

Steps to Reproduce:
1. Create a new iOS single view app project in Xcode 7
2. Change the view controller’s implementation file extension to .mm
3. In the viewDidLoad method, after the super call add the line `auto view = self.view;`
4. Copy and paste the code snippets from the description in there.
5. Observe the types in the auto completion list when you type `viewsT` and `intere`

Expected Results:
`intere` yields `interestingViews` with a type of `NSArray<__kindof UIView *> *const` in the auto complete list, `viewsT` yields `viewsToFilter` with a type of `NSMutableArray<__kindof UIView *> *const` in the auto complete list

Actual Results:
`intere` yields `interestingViews` with a type of `NSArray<__kindof UIView *> *const` in the auto complete list — that’s good.

`viewsT` yields `viewsToFilter` with a type of `NSMutableArray *const` in the auto complete list — that’s bad: the type annotation has been swallowed.

Version:
Happens in all Xcode 7 seeds, last checked with Version 7.0 beta 3 (7A152u)

Notes:


Configuration:


Attachments:

---

Apple Developer Relations13-Jul-2015 09:18 PM

There are no plans to address this based on the following:

The C type system is hostile to this, because things like "auto x = 42" will not produce an NSInteger, among many other problems.

We are now closing this report.

If you have questions about the resolution, or if this is still a critical issue for you, then please update your bug report with that information.

Please be sure to regularly check new Apple releases for any updates that might affect this issue.

---

Apple Developer Relations15-Sep-2015 05:29 AM

Engineering has determined that your bug report is a duplicate of another issue and will be closed. 

The open or closed status of the original bug report your issue was duplicated to appears in the yellow "Duplicate of XXXXXXXX" section of the bug reporter user interface. This section appears near the top of the right column's bug detail view just under the bug number, title, state, product and rank.

If you have any questions or concerns, please update your report directly here: http://bugreport.apple.com/.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!