1*f4a2713aSLionel Sambuc // RUN: rm -rf %t 2*f4a2713aSLionel Sambuc // RUN: not %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-lookups | FileCheck %s --check-prefix=CHECK-GLOBAL 3*f4a2713aSLionel Sambuc // RUN: not %clang_cc1 -x objective-c++ -fmodules -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*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11 5*f4a2713aSLionel Sambuc 6*f4a2713aSLionel Sambuc @import cxx_templates_a; 7*f4a2713aSLionel Sambuc @import cxx_templates_b; 8*f4a2713aSLionel Sambuc @import cxx_templates_c; 9*f4a2713aSLionel Sambuc @import cxx_templates_common; 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc template<typename, char> struct Tmpl_T_C {}; 12*f4a2713aSLionel Sambuc template<typename, int, int> struct Tmpl_T_I_I {}; 13*f4a2713aSLionel Sambuc 14*f4a2713aSLionel Sambuc template<typename A, typename B, A> struct Tmpl_T_T_A {}; 15*f4a2713aSLionel Sambuc template<typename A, typename B, B> struct Tmpl_T_T_B {}; 16*f4a2713aSLionel Sambuc 17*f4a2713aSLionel Sambuc template<int> struct UseInt {}; 18*f4a2713aSLionel Sambuc 19*f4a2713aSLionel Sambuc void g() { 20*f4a2713aSLionel Sambuc f(0); 21*f4a2713aSLionel Sambuc f<double>(1.0); 22*f4a2713aSLionel Sambuc f<int>(); 23*f4a2713aSLionel Sambuc f(); // expected-error {{no matching function}} 24*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-b.h:3 {{couldn't infer template argument}} 25*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-b.h:4 {{requires single argument}} 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambuc N::f(0); 28*f4a2713aSLionel Sambuc N::f<double>(1.0); 29*f4a2713aSLionel Sambuc N::f<int>(); 30*f4a2713aSLionel Sambuc N::f(); // expected-error {{no matching function}} 31*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-b.h:6 {{couldn't infer template argument}} 32*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-b.h:7 {{requires single argument 't'}} 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambuc template_param_kinds_1<0>(); // ok, from cxx-templates-a.h 35*f4a2713aSLionel Sambuc template_param_kinds_1<int>(); // ok, from cxx-templates-b.h 36*f4a2713aSLionel Sambuc 37*f4a2713aSLionel Sambuc template_param_kinds_2<Tmpl_T_C>(); // expected-error {{no matching function}} 38*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-a.h:11 {{invalid explicitly-specified argument}} 39*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-b.h:11 {{invalid explicitly-specified argument}} 40*f4a2713aSLionel Sambuc 41*f4a2713aSLionel Sambuc template_param_kinds_2<Tmpl_T_I_I>(); // expected-error {{ambiguous}} 42*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-a.h:11 {{candidate}} 43*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-b.h:11 {{candidate}} 44*f4a2713aSLionel Sambuc 45*f4a2713aSLionel Sambuc // FIXME: This should be valid, but we incorrectly match the template template 46*f4a2713aSLionel Sambuc // argument against both template template parameters. 47*f4a2713aSLionel Sambuc template_param_kinds_3<Tmpl_T_T_A>(); // expected-error {{ambiguous}} 48*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}} 49*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}} 50*f4a2713aSLionel Sambuc template_param_kinds_3<Tmpl_T_T_B>(); // expected-error {{ambiguous}} 51*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}} 52*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}} 53*f4a2713aSLionel Sambuc 54*f4a2713aSLionel Sambuc // Trigger the instantiation of a template in 'a' that uses a type defined in 55*f4a2713aSLionel Sambuc // 'common'. That type is not visible here. 56*f4a2713aSLionel Sambuc PerformDelayedLookup(defined_in_common); 57*f4a2713aSLionel Sambuc 58*f4a2713aSLionel Sambuc // Likewise, but via a default argument. 59*f4a2713aSLionel Sambuc PerformDelayedLookupInDefaultArgument(defined_in_common); 60*f4a2713aSLionel Sambuc 61*f4a2713aSLionel Sambuc // Trigger the instantiation of a template in 'b' that uses a type defined in 62*f4a2713aSLionel Sambuc // 'b_impl'. That type is not visible here. 63*f4a2713aSLionel Sambuc UseDefinedInBImpl<int>(); 64*f4a2713aSLionel Sambuc 65*f4a2713aSLionel Sambuc // Trigger the instantiation of a template in 'a' that uses a type defined in 66*f4a2713aSLionel Sambuc // 'b_impl', via a template defined in 'b'. Since the type is visible from 67*f4a2713aSLionel Sambuc // within 'b', the instantiation succeeds. 68*f4a2713aSLionel Sambuc UseDefinedInBImplIndirectly(defined_in_b_impl); 69*f4a2713aSLionel Sambuc 70*f4a2713aSLionel Sambuc // Trigger the instantiation of a template in 'a' that uses a type defined in 71*f4a2713aSLionel Sambuc // 'b_impl'. That type is not visible here, nor in 'a'. This fails; there is 72*f4a2713aSLionel Sambuc // no reason why DefinedInBImpl should be visible here. 73*f4a2713aSLionel Sambuc // expected-error@Inputs/cxx-templates-a.h:19 {{definition of 'DefinedInBImpl' must be imported}} 74*f4a2713aSLionel Sambuc // expected-note@Inputs/cxx-templates-b-impl.h:1 {{definition is here}} 75*f4a2713aSLionel Sambuc PerformDelayedLookup(defined_in_b_impl); // expected-note {{in instantiation of}} 76*f4a2713aSLionel Sambuc 77*f4a2713aSLionel Sambuc merge_templates_a = merge_templates_b; // ok, same type 78*f4a2713aSLionel Sambuc 79*f4a2713aSLionel Sambuc using T = decltype(enum_a_from_a); 80*f4a2713aSLionel Sambuc using T = decltype(enum_b_from_b); 81*f4a2713aSLionel Sambuc T e = true ? enum_a_from_a : enum_b_from_b; 82*f4a2713aSLionel Sambuc 83*f4a2713aSLionel Sambuc UseRedeclaredEnum<int>(UseInt<1>()); 84*f4a2713aSLionel Sambuc // FIXME: Reintroduce this once we merge function template specializations. 85*f4a2713aSLionel Sambuc //static_assert(UseRedeclaredEnumA == UseRedeclaredEnumB, ""); 86*f4a2713aSLionel Sambuc //static_assert(UseRedeclaredEnumA == UseRedeclaredEnum<int>, ""); 87*f4a2713aSLionel Sambuc //static_assert(UseRedeclaredEnumB == UseRedeclaredEnum<int>, ""); 88*f4a2713aSLionel Sambuc static_assert(enum_c_from_a == enum_c_from_b, ""); 89*f4a2713aSLionel Sambuc CommonTemplate<int> cti; 90*f4a2713aSLionel Sambuc CommonTemplate<int>::E eee = CommonTemplate<int>::c; 91*f4a2713aSLionel Sambuc } 92*f4a2713aSLionel Sambuc 93*f4a2713aSLionel Sambuc RedeclaredAsFriend<int> raf1; 94*f4a2713aSLionel Sambuc RedeclareTemplateAsFriend<double> rtaf; 95*f4a2713aSLionel Sambuc RedeclaredAsFriend<double> raf2; 96*f4a2713aSLionel Sambuc 97*f4a2713aSLionel Sambuc MergeSpecializations<int*>::partially_specialized_in_a spec_in_a_1; 98*f4a2713aSLionel Sambuc MergeSpecializations<int&>::partially_specialized_in_b spec_in_b_1; 99*f4a2713aSLionel Sambuc MergeSpecializations<int[]>::partially_specialized_in_c spec_in_c_1; 100*f4a2713aSLionel Sambuc MergeSpecializations<char>::explicitly_specialized_in_a spec_in_a_2; 101*f4a2713aSLionel Sambuc MergeSpecializations<double>::explicitly_specialized_in_b spec_in_b_2; 102*f4a2713aSLionel Sambuc MergeSpecializations<bool>::explicitly_specialized_in_c spec_in_c_2; 103*f4a2713aSLionel Sambuc 104*f4a2713aSLionel Sambuc @import cxx_templates_common; 105*f4a2713aSLionel Sambuc 106*f4a2713aSLionel Sambuc typedef SomeTemplate<int*> SomeTemplateIntPtr; 107*f4a2713aSLionel Sambuc typedef SomeTemplate<int&> SomeTemplateIntRef; 108*f4a2713aSLionel Sambuc SomeTemplate<char*> some_template_char_ptr; 109*f4a2713aSLionel Sambuc SomeTemplate<char&> some_template_char_ref; 110*f4a2713aSLionel Sambuc 111*f4a2713aSLionel Sambuc void testImplicitSpecialMembers(SomeTemplate<char[1]> &a, 112*f4a2713aSLionel Sambuc const SomeTemplate<char[1]> &b, 113*f4a2713aSLionel Sambuc SomeTemplate<char[2]> &c, 114*f4a2713aSLionel Sambuc const SomeTemplate<char[2]> &d) { 115*f4a2713aSLionel Sambuc a = b; 116*f4a2713aSLionel Sambuc c = d; 117*f4a2713aSLionel Sambuc } 118*f4a2713aSLionel Sambuc 119*f4a2713aSLionel Sambuc // CHECK-GLOBAL: DeclarationName 'f' 120*f4a2713aSLionel Sambuc // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f' 121*f4a2713aSLionel Sambuc // CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f' 122*f4a2713aSLionel Sambuc 123*f4a2713aSLionel Sambuc // CHECK-NAMESPACE-N: DeclarationName 'f' 124*f4a2713aSLionel Sambuc // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f' 125*f4a2713aSLionel Sambuc // CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f' 126