Skip to content

Instantly share code, notes, and snippets.

@idoru
Last active December 16, 2015 17:29
Show Gist options
  • Save idoru/5470286 to your computer and use it in GitHub Desktop.
Save idoru/5470286 to your computer and use it in GitHub Desktop.
Clang with ARC bug: Incorrect substitution for pointer template parameters. This bug report is suitable to be posted to http://bugreport.apple.com
Summary:
When ARC is enabled, C++ candidate templates' pointer template parameters are not correctly substituted for objective-C object pointers.
Steps to reproduce:
Compile the following main.mm file, with and without ARC:
#import <Foundation/Foundation.h>
template <typename T>
void testing(const T & whoCares) {
NSLog(@"================> Non pointer template");
}
template <typename T>
void testing(T * const & whoCares) {
NSLog(@"================> Pointer template");
}
int main(int argc, const char * argv[])
{
NSString *stringObject = @"hi";
char *cString = "abc";
testing(1);
testing(cString);
testing(stringObject);
testing<NSString>(stringObject);
return 0;
}
Expected Results:
The template with the pointer parameter should be instantiated for cString and stringObject, without needing to parameterize the template explicitly, as demonstrated by the output when compiled without ARC:
================> Non pointer template
================> Pointer template
================> Pointer template
================> Pointer template
Actual Results:
When ARC is enabled and the template is not parameterized explicitly, the non-pointer template is instantiated if the pointer is an objective-c type, as demonstrated by the output when compiled with ARC:
================> Non pointer template
================> Pointer template
================> Non pointer template <== WRONG
================> Pointer template
Regression:
Notes:
It seems clear that the substitution is incorrect since there is a more specialized template for T * const, which should be elected instead of const T for NSString *.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment