Skip to content

Instantly share code, notes, and snippets.

@idoru
Created July 13, 2012 02:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save idoru/3102360 to your computer and use it in GitHub Desktop.
Clang with ARC bug: Incorrect Template substitution failure
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment