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