public
Created

Clang with ARC bug: Incorrect Template substitution failure

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
Summary:
When ARC is enabled, C++ candidate templates are ignored due to an incorrectly diagnosed substitution failure.
 
 
Steps to Reproduce:
Compile the following main.mm file, with and without ARC:
 
#import <Foundation/Foundation.h>
 
template <typename T>
int testing(const T & whoCares) {
return 1;
}
 
int main(int argc, const char * argv[])
{
printf("%d\n", testing(1));
printf("%d\n", testing("hi"));
printf("%d\n", testing<NSString *>(@"hi"));
printf("%d\n", testing(@"hi"));
return 0;
}
 
 
Expected Results:
It should work whether or not ARC is enabled.
 
 
Actual Results:
Compilation fails with error:
main.mm:13:20: error: no matching function for call to 'testing'
printf("%d\n", testing(@"hi"));
^~~~~~~
main.mm:4:5: note: candidate template ignored: substitution failure
[with T = NSString *]
int testing(const T & whoCares) {
^
1 error generated.
 
 
Regression:
 
 
Notes:
It seems clear that the substitution failure is an incorrect determination since the template obviously works fine on line 12 where the type is being passed. AFAIK this has been broken ever since ARC was introduced.
 
This happens regardless of platform (iOS, Mac OS X) and is still present in Xcode 4.3.3 as well as the 4.5 developer preview 2.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.