[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaObjCXX / instantiate-message.mm
blobe09b1829e300c6f50c868c6c1d7ee1a55f0a71c9
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 // Test template instantiation of Objective-C message sends.
5 @interface ClassMethods
6 + (ClassMethods *)method1:(void*)ptr;
7 @end
9 template<typename T>
10 struct identity {
11   typedef T type;
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 *'}}
21 template void test_class_method<ClassMethods, ClassMethods>(void*);
22 template void test_class_method<ClassMethods, ClassMethods>(int*);
24 @interface ClassMethods2
25 + (ClassMethods2 *)method1:(int*)ptr;
26 @end
28 template void test_class_method<ClassMethods2, ClassMethods2>(int*); // expected-note{{in instantiation of}}
31 @interface InstanceMethods
32 - (InstanceMethods *)method1:(void*)ptr;
33 @end
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 *'}}
43 template void test_instance_method<InstanceMethods, InstanceMethods>(void*);
44 template void test_instance_method<InstanceMethods, InstanceMethods>(int*);
46 @interface InstanceMethods2
47 - (InstanceMethods2 *)method1:(void*)ptr;
48 @end
50 template void test_instance_method<InstanceMethods2, InstanceMethods2>(int*); // expected-note{{in instantiation of}}