Skip to content

Instantly share code, notes, and snippets.



Created Jul 13, 2012
What would you like to do?
Clang with ARC bug: Incorrect Template substitution failure
When ARC is enabled, C++ candidate templates are ignored due to an incorrectly diagnosed substitution failure.
Steps to Reproduce:
Compile the following 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: error: no matching function for call to 'testing'
printf("%d\n", testing(@"hi"));
^~~~~~~ note: candidate template ignored: substitution failure
[with T = NSString *]
int testing(const T & whoCares) {
1 error generated.
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