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-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-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 // RUN: %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11 -DEARLY_IMPORT 7 8 #ifdef EARLY_IMPORT 9 #include "cxx-templates-textual.h" 10 #endif 11 12 @import cxx_templates_a; 13 @import cxx_templates_b; 14 @import cxx_templates_c; 15 @import cxx_templates_d; 16 @import cxx_templates_common; 17 18 template<typename, char> struct Tmpl_T_C {}; 19 template<typename, int, int> struct Tmpl_T_I_I {}; 20 21 template<typename A, typename B, A> struct Tmpl_T_T_A {}; 22 template<typename A, typename B, B> struct Tmpl_T_T_B {}; 23 24 template<int> struct UseInt {}; 25 26 void g() { 27 f(0); 28 f<double>(1.0); 29 f<int>(); 30 f(); // expected-error {{no matching function}} 31 // expected-note@Inputs/cxx-templates-b.h:3 {{couldn't infer template argument}} 32 // expected-note@Inputs/cxx-templates-b.h:4 {{requires single argument}} 33 34 N::f(0); 35 N::f<double>(1.0); 36 N::f<int>(); 37 N::f(); // expected-error {{no matching function}} 38 // expected-note@Inputs/cxx-templates-b.h:6 {{couldn't infer template argument}} 39 // expected-note@Inputs/cxx-templates-b.h:7 {{requires single argument}} 40 41 template_param_kinds_1<0>(); // ok, from cxx-templates-a.h 42 template_param_kinds_1<int>(); // ok, from cxx-templates-b.h 43 44 template_param_kinds_2<Tmpl_T_C>(); // expected-error {{no matching function}} 45 // expected-note@Inputs/cxx-templates-a.h:11 {{invalid explicitly-specified argument}} 46 // expected-note@Inputs/cxx-templates-b.h:11 {{invalid explicitly-specified argument}} 47 48 template_param_kinds_2<Tmpl_T_I_I>(); // expected-error {{ambiguous}} 49 // expected-note@Inputs/cxx-templates-a.h:11 {{candidate}} 50 // expected-note@Inputs/cxx-templates-b.h:11 {{candidate}} 51 52 // FIXME: This should be valid, but we incorrectly match the template template 53 // argument against both template template parameters. 54 template_param_kinds_3<Tmpl_T_T_A>(); // expected-error {{ambiguous}} 55 // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}} 56 // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}} 57 template_param_kinds_3<Tmpl_T_T_B>(); // expected-error {{ambiguous}} 58 // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}} 59 // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}} 60 61 // Trigger the instantiation of a template in 'a' that uses a type defined in 62 // 'common'. That type is not visible here. 63 PerformDelayedLookup(defined_in_common); 64 65 // Likewise, but via a default argument. 66 PerformDelayedLookupInDefaultArgument(defined_in_common); 67 68 // Trigger the instantiation of a template in 'b' that uses a type defined in 69 // 'b_impl'. That type is not visible here. 70 UseDefinedInBImpl<int>(); 71 72 // Trigger the instantiation of a template in 'a' that uses a type defined in 73 // 'b_impl', via a template defined in 'b'. Since the type is visible from 74 // within 'b', the instantiation succeeds. 75 UseDefinedInBImplIndirectly(defined_in_b_impl); 76 77 // Trigger the instantiation of a template in 'a' that uses a type defined in 78 // 'b_impl'. That type is not visible here, nor in 'a'. This fails; there is 79 // no reason why DefinedInBImpl should be visible here. 80 // 81 // We turn off error recovery for modules in this test (so we don't get an 82 // implicit import of cxx_templates_b_impl), and that results in us producing 83 // a big spew of errors here. 84 // 85 // expected-error@Inputs/cxx-templates-a.h:19 {{definition of 'DefinedInBImpl' must be imported}} 86 // expected-note@Inputs/cxx-templates-b-impl.h:1 +{{definition is here}} 87 // expected-error@Inputs/cxx-templates-a.h:19 +{{}} 88 // expected-error@Inputs/cxx-templates-a.h:20 +{{}} 89 PerformDelayedLookup(defined_in_b_impl); // expected-note {{in instantiation of}} 90 91 merge_templates_a = merge_templates_b; // ok, same type 92 93 using T = decltype(enum_a_from_a); 94 using T = decltype(enum_b_from_b); 95 T e = true ? enum_a_from_a : enum_b_from_b; 96 97 UseRedeclaredEnum<int>(UseInt<1>()); 98 // FIXME: Reintroduce this once we merge function template specializations. 99 //static_assert(UseRedeclaredEnumA == UseRedeclaredEnumB, ""); 100 //static_assert(UseRedeclaredEnumA == UseRedeclaredEnum<int>, ""); 101 //static_assert(UseRedeclaredEnumB == UseRedeclaredEnum<int>, ""); 102 static_assert(enum_c_from_a == enum_c_from_b, ""); 103 CommonTemplate<int> cti; 104 CommonTemplate<int>::E eee = CommonTemplate<int>::c; 105 106 TemplateInstantiationVisibility<char[1]> tiv1; 107 TemplateInstantiationVisibility<char[2]> tiv2; 108 TemplateInstantiationVisibility<char[3]> tiv3; // expected-error {{must be imported from module 'cxx_templates_b_impl'}} 109 // [email protected]:10 {{previous definition is here}} 110 TemplateInstantiationVisibility<char[4]> tiv4; 111 112 int &p = WithPartialSpecializationUse().f(); 113 int &q = WithExplicitSpecializationUse().inner_template<int>(); 114 int *r = PartiallyInstantiatePartialSpec<int*>::bar(); 115 116 (void)&WithImplicitSpecialMembers<int>::n; 117 118 MergeClassTemplateSpecializations_string s; 119 120 extern TestInjectedClassName::A *use_a; 121 extern TestInjectedClassName::C *use_c; 122 TestInjectedClassName::UseD(); 123 } 124 125 static_assert(Outer<int>::Inner<int>::f() == 1, ""); 126 static_assert(Outer<int>::Inner<int>::g() == 2, ""); 127 128 #ifndef EARLY_IMPORT 129 // FIXME: The textual inclusion above shouldn't cause this to fail! 130 static_assert(MergeTemplateDefinitions<int>::f() == 1, ""); 131 static_assert(MergeTemplateDefinitions<int>::g() == 2, ""); 132 133 RedeclaredAsFriend<int> raf1; 134 RedeclareTemplateAsFriend<double> rtaf; 135 RedeclaredAsFriend<double> raf2; 136 137 MergeSpecializations<int*>::partially_specialized_in_a spec_in_a_1; 138 MergeSpecializations<int&>::partially_specialized_in_b spec_in_b_1; 139 MergeSpecializations<int[]>::partially_specialized_in_c spec_in_c_1; 140 MergeSpecializations<char>::explicitly_specialized_in_a spec_in_a_2; 141 MergeSpecializations<double>::explicitly_specialized_in_b spec_in_b_2; 142 MergeSpecializations<bool>::explicitly_specialized_in_c spec_in_c_2; 143 #endif 144 145 MergeAnonUnionMember<> maum_main; 146 typedef DontWalkPreviousDeclAfterMerging<int> dwpdam_typedef_2; 147 dwpdam_typedef::type dwpdam_typedef_use; 148 DontWalkPreviousDeclAfterMerging<int>::Inner::type dwpdam; 149 150 using AliasTemplateMergingTest = WithAliasTemplate<int>::X<char>; 151 152 int AnonymousDeclsMergingTest(WithAnonymousDecls<int> WAD, WithAnonymousDecls<char> WADC) { 153 return InstantiateWithAnonymousDeclsA(WAD) + 154 InstantiateWithAnonymousDeclsB(WAD) + 155 InstantiateWithAnonymousDeclsB2(WADC) + 156 InstantiateWithAnonymousDeclsD(WADC); 157 } 158 159 @import cxx_templates_common; 160 161 typedef SomeTemplate<int*> SomeTemplateIntPtr; 162 typedef SomeTemplate<int&> SomeTemplateIntRef; 163 SomeTemplate<char*> some_template_char_ptr; 164 SomeTemplate<char&> some_template_char_ref; 165 166 void testImplicitSpecialMembers(SomeTemplate<char[1]> &a, 167 const SomeTemplate<char[1]> &b, 168 SomeTemplate<char[2]> &c, 169 const SomeTemplate<char[2]> &d) { 170 a = b; 171 c = d; 172 } 173 174 bool testFriendInClassTemplate(Std::WithFriend<int> wfi) { 175 return wfi != wfi; 176 } 177 178 namespace Std { 179 void g(); // expected-error {{functions that differ only in their return type cannot be overloaded}} 180 // [email protected]:21 {{previous}} 181 } 182 183 // CHECK-GLOBAL: DeclarationName 'f' 184 // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f' 185 // CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f' 186 187 // CHECK-NAMESPACE-N: DeclarationName 'f' 188 // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f' 189 // CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f' 190 191 // CHECK-DUMP: ClassTemplateDecl {{.*}} <{{.*[/\\]}}cxx-templates-common.h:1:1, {{.*}}> col:{{.*}} in cxx_templates_common SomeTemplate 192 // CHECK-DUMP: ClassTemplateSpecializationDecl {{.*}} prev {{.*}} SomeTemplate 193 // CHECK-DUMP-NEXT: TemplateArgument type 'char [2]' 194 // CHECK-DUMP: ClassTemplateSpecializationDecl {{.*}} SomeTemplate definition 195 // CHECK-DUMP-NEXT: TemplateArgument type 'char [2]' 196 // CHECK-DUMP: ClassTemplateSpecializationDecl {{.*}} prev {{.*}} SomeTemplate 197 // CHECK-DUMP-NEXT: TemplateArgument type 'char [1]' 198 // CHECK-DUMP: ClassTemplateSpecializationDecl {{.*}} SomeTemplate definition 199 // CHECK-DUMP-NEXT: TemplateArgument type 'char [1]' 200