• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: rm -rf %t
2 // RUN: not %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-lookups | FileCheck %s --check-prefix=CHECK-GLOBAL
3 // RUN: not %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-lookups -ast-dump-filter N | FileCheck %s --check-prefix=CHECK-NAMESPACE-N
4 // RUN: not %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump | FileCheck %s --check-prefix=CHECK-DUMP
5 // RUN: %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11
6 
7 @import cxx_templates_a;
8 @import cxx_templates_b;
9 @import cxx_templates_c;
10 @import cxx_templates_common;
11 
12 template<typename, char> struct Tmpl_T_C {};
13 template<typename, int, int> struct Tmpl_T_I_I {};
14 
15 template<typename A, typename B, A> struct Tmpl_T_T_A {};
16 template<typename A, typename B, B> struct Tmpl_T_T_B {};
17 
18 template<int> struct UseInt {};
19 
g()20 void g() {
21   f(0);
22   f<double>(1.0);
23   f<int>();
24   f(); // expected-error {{no matching function}}
25   // expected-note@Inputs/cxx-templates-b.h:3 {{couldn't infer template argument}}
26   // expected-note@Inputs/cxx-templates-b.h:4 {{requires single argument}}
27 
28   N::f(0);
29   N::f<double>(1.0);
30   N::f<int>();
31   N::f(); // expected-error {{no matching function}}
32   // expected-note@Inputs/cxx-templates-a.h:6 {{couldn't infer template argument}}
33   // expected-note@Inputs/cxx-templates-a.h:7 {{requires 1 argument}}
34 
35   template_param_kinds_1<0>(); // ok, from cxx-templates-a.h
36   template_param_kinds_1<int>(); // ok, from cxx-templates-b.h
37 
38   template_param_kinds_2<Tmpl_T_C>(); // expected-error {{no matching function}}
39   // expected-note@Inputs/cxx-templates-a.h:11 {{invalid explicitly-specified argument}}
40   // expected-note@Inputs/cxx-templates-b.h:11 {{invalid explicitly-specified argument}}
41 
42   template_param_kinds_2<Tmpl_T_I_I>(); // expected-error {{ambiguous}}
43   // expected-note@Inputs/cxx-templates-a.h:11 {{candidate}}
44   // expected-note@Inputs/cxx-templates-b.h:11 {{candidate}}
45 
46   // FIXME: This should be valid, but we incorrectly match the template template
47   // argument against both template template parameters.
48   template_param_kinds_3<Tmpl_T_T_A>(); // expected-error {{ambiguous}}
49   // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}}
50   // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}}
51   template_param_kinds_3<Tmpl_T_T_B>(); // expected-error {{ambiguous}}
52   // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}}
53   // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}}
54 
55   // Trigger the instantiation of a template in 'a' that uses a type defined in
56   // 'common'. That type is not visible here.
57   PerformDelayedLookup(defined_in_common);
58 
59   // Likewise, but via a default argument.
60   PerformDelayedLookupInDefaultArgument(defined_in_common);
61 
62   // Trigger the instantiation of a template in 'b' that uses a type defined in
63   // 'b_impl'. That type is not visible here.
64   UseDefinedInBImpl<int>();
65 
66   // Trigger the instantiation of a template in 'a' that uses a type defined in
67   // 'b_impl', via a template defined in 'b'. Since the type is visible from
68   // within 'b', the instantiation succeeds.
69   UseDefinedInBImplIndirectly(defined_in_b_impl);
70 
71   // Trigger the instantiation of a template in 'a' that uses a type defined in
72   // 'b_impl'. That type is not visible here, nor in 'a'. This fails; there is
73   // no reason why DefinedInBImpl should be visible here.
74   //
75   // We turn off error recovery for modules in this test (so we don't get an
76   // implicit import of cxx_templates_b_impl), and that results in us producing
77   // a big spew of errors here.
78   //
79   // expected-error@Inputs/cxx-templates-a.h:19 {{definition of 'DefinedInBImpl' must be imported}}
80   // expected-note@Inputs/cxx-templates-b-impl.h:1 +{{definition is here}}
81   // expected-error@Inputs/cxx-templates-a.h:19 +{{}}
82   // expected-error@Inputs/cxx-templates-a.h:20 +{{}}
83   PerformDelayedLookup(defined_in_b_impl); // expected-note {{in instantiation of}}
84 
85   merge_templates_a = merge_templates_b; // ok, same type
86 
87   using T = decltype(enum_a_from_a);
88   using T = decltype(enum_b_from_b);
89   T e = true ? enum_a_from_a : enum_b_from_b;
90 
91   UseRedeclaredEnum<int>(UseInt<1>());
92   // FIXME: Reintroduce this once we merge function template specializations.
93   //static_assert(UseRedeclaredEnumA == UseRedeclaredEnumB, "");
94   //static_assert(UseRedeclaredEnumA == UseRedeclaredEnum<int>, "");
95   //static_assert(UseRedeclaredEnumB == UseRedeclaredEnum<int>, "");
96   static_assert(enum_c_from_a == enum_c_from_b, "");
97   CommonTemplate<int> cti;
98   CommonTemplate<int>::E eee = CommonTemplate<int>::c;
99 
100   TemplateInstantiationVisibility<char[1]> tiv1;
101   TemplateInstantiationVisibility<char[2]> tiv2;
102   TemplateInstantiationVisibility<char[3]> tiv3; // expected-error {{must be imported from module 'cxx_templates_b_impl'}}
103   // expected-note@cxx-templates-b-impl.h:10 {{previous definition is here}}
104   TemplateInstantiationVisibility<char[4]> tiv4;
105 
106   int &p = WithPartialSpecializationUse().f();
107   int &q = WithExplicitSpecializationUse().inner_template<int>();
108 }
109 
110 RedeclaredAsFriend<int> raf1;
111 RedeclareTemplateAsFriend<double> rtaf;
112 RedeclaredAsFriend<double> raf2;
113 
114 MergeSpecializations<int*>::partially_specialized_in_a spec_in_a_1;
115 MergeSpecializations<int&>::partially_specialized_in_b spec_in_b_1;
116 MergeSpecializations<int[]>::partially_specialized_in_c spec_in_c_1;
117 MergeSpecializations<char>::explicitly_specialized_in_a spec_in_a_2;
118 MergeSpecializations<double>::explicitly_specialized_in_b spec_in_b_2;
119 MergeSpecializations<bool>::explicitly_specialized_in_c spec_in_c_2;
120 
121 @import cxx_templates_common;
122 
123 typedef SomeTemplate<int*> SomeTemplateIntPtr;
124 typedef SomeTemplate<int&> SomeTemplateIntRef;
125 SomeTemplate<char*> some_template_char_ptr;
126 SomeTemplate<char&> some_template_char_ref;
127 
testImplicitSpecialMembers(SomeTemplate<char[1]> & a,const SomeTemplate<char[1]> & b,SomeTemplate<char[2]> & c,const SomeTemplate<char[2]> & d)128 void testImplicitSpecialMembers(SomeTemplate<char[1]> &a,
129                                 const SomeTemplate<char[1]> &b,
130                                 SomeTemplate<char[2]> &c,
131                                 const SomeTemplate<char[2]> &d) {
132   a = b;
133   c = d;
134 }
135 
testFriendInClassTemplate(Std::WithFriend<int> wfi)136 bool testFriendInClassTemplate(Std::WithFriend<int> wfi) {
137   return wfi != wfi;
138 }
139 
140 namespace Std {
141   void g(); // expected-error {{functions that differ only in their return type cannot be overloaded}}
142   // expected-note@cxx-templates-common.h:21 {{previous}}
143 }
144 
145 // CHECK-GLOBAL:      DeclarationName 'f'
146 // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
147 // CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f'
148 
149 // CHECK-NAMESPACE-N:      DeclarationName 'f'
150 // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
151 // CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f'
152 
153 // CHECK-DUMP:      ClassTemplateDecl {{.*}} <{{.*[/\\]}}cxx-templates-common.h:1:1, {{.*}}>  col:{{.*}} in cxx_templates_common SomeTemplate
154 // CHECK-DUMP:        ClassTemplateSpecializationDecl {{.*}} prev [[CHAR2:[^ ]*]] {{.*}} SomeTemplate
155 // CHECK-DUMP-NEXT:     TemplateArgument type 'char [2]'
156 // CHECK-DUMP:        ClassTemplateSpecializationDecl [[CHAR2]] {{.*}} SomeTemplate definition
157 // CHECK-DUMP-NEXT:     TemplateArgument type 'char [2]'
158 // CHECK-DUMP:        ClassTemplateSpecializationDecl {{.*}} prev [[CHAR1:[^ ]*]] {{.*}} SomeTemplate
159 // CHECK-DUMP-NEXT:     TemplateArgument type 'char [1]'
160 // CHECK-DUMP:        ClassTemplateSpecializationDecl [[CHAR1]] {{.*}} SomeTemplate definition
161 // CHECK-DUMP-NEXT:     TemplateArgument type 'char [1]'
162