Home | History | Annotate | Download | only in SemaObjCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 
      3 // Test template instantiation of Objective-C message sends.
      4 
      5 @interface ClassMethods
      6 + (ClassMethods *)method1:(void*)ptr;
      7 @end
      8 
      9 template<typename T>
     10 struct identity {
     11   typedef T type;
     12 };
     13 
     14 template<typename R, typename T, typename Arg1>
     15 void test_class_method(Arg1 arg1) {
     16   R *result1 = [T method1:arg1];
     17   R *result2 = [typename identity<T>::type method1:arg1];
     18   R *result3 = [ClassMethods method1:arg1]; // expected-error{{cannot initialize a variable of type 'ClassMethods2 *' with an rvalue of type 'ClassMethods *'}}
     19 }
     20 
     21 template void test_class_method<ClassMethods, ClassMethods>(void*);
     22 template void test_class_method<ClassMethods, ClassMethods>(int*);
     23 
     24 @interface ClassMethods2
     25 + (ClassMethods2 *)method1:(int*)ptr;
     26 @end
     27 
     28 template void test_class_method<ClassMethods2, ClassMethods2>(int*); // expected-note{{in instantiation of}}
     29 
     30 
     31 @interface InstanceMethods
     32 - (InstanceMethods *)method1:(void*)ptr;
     33 @end
     34 
     35 template<typename R, typename T, typename Arg1>
     36 void test_instance_method(Arg1 arg1) {
     37   T *receiver = 0;
     38   InstanceMethods *im = 0;
     39   R *result1 = [receiver method1:arg1];
     40   R *result2 = [im method1:arg1]; // expected-error{{cannot initialize a variable of type 'InstanceMethods2 *' with an rvalue of type 'InstanceMethods *'}}
     41 }
     42 
     43 template void test_instance_method<InstanceMethods, InstanceMethods>(void*);
     44 template void test_instance_method<InstanceMethods, InstanceMethods>(int*);
     45 
     46 @interface InstanceMethods2
     47 - (InstanceMethods2 *)method1:(void*)ptr;
     48 @end
     49 
     50 template void test_instance_method<InstanceMethods2, InstanceMethods2>(int*); // expected-note{{in instantiation of}}
     51