Compiler is unable to resolve element type in for-in loop when using "auto" keyword

Originator:and.mikhaylov
Number:rdar://22756333 Date Originated:18-Sep-2015 02:27 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7
Classification:Other Bug Reproducible:Always
 
Summary:
Since Xcode 7 we have ability to use lightweight generics that come pretty handy and especially in Objective-C++ where we can use “auto” keyword to avoid typing pretty long typename declarations. 

Unfortunately “auto” keyword does not work properly with lightweight generics in for-in loops and unable to resolve element type of iterated array and falls back to “id”.

Compiler must be able to resolve the typename of object in iterated array. 

NSFastEnumeration, on the other hand, works properly and Xcode suggests the right typename when using enumerateObjectsUsingBlock.

Example: 

   NSArray<UILocalNotification *> *localNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
    
    for(auto notification in localNotifications) {
        if([notification.userInfo[@"isGameActivityNotification"] boolValue]) {
            [[UIApplication sharedApplication] cancelLocalNotification:notification];
        }
    }

Steps to Reproduce:

Expected Results:
“auto” is deduced as “element type” of iterated array.

Actual Results:
Compiler throws warning “‘auto’ deduced as ‘id’ in declaration of ‘notification’”

Regression:

Notes:

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!