blob: 0965aa8b0bcb864fd2daf0cf3f3b8cf23ef526a4 [file] [log] [blame]
Richard Smith8f8f05c2013-06-24 04:45:28 +00001// RUN: rm -rf %t
Rafael Espindola925213b2013-07-04 16:16:58 +00002// 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
Richard Smith8f8f05c2013-06-24 04:45:28 +00004// 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;
Richard Smith01a73372013-10-15 22:02:41 +00008@import cxx_templates_common;
Richard Smith8f8f05c2013-06-24 04:45:28 +00009
Richard Smithbf78e642013-06-24 22:51:00 +000010template<typename, char> struct Tmpl_T_C {};
11template<typename, int, int> struct Tmpl_T_I_I {};
12
13template<typename A, typename B, A> struct Tmpl_T_T_A {};
14template<typename A, typename B, B> struct Tmpl_T_T_B {};
15
Richard Smith01a73372013-10-15 22:02:41 +000016template<int> struct UseInt {};
17
Richard Smith8f8f05c2013-06-24 04:45:28 +000018void g() {
19 f(0);
20 f<double>(1.0);
21 f<int>();
22 f(); // expected-error {{no matching function}}
Richard Smith5de91b52013-06-25 01:25:15 +000023 // expected-note@Inputs/cxx-templates-b.h:3 {{couldn't infer template argument}}
24 // expected-note@Inputs/cxx-templates-b.h:4 {{requires single argument}}
Richard Smith8f8f05c2013-06-24 04:45:28 +000025
26 N::f(0);
27 N::f<double>(1.0);
28 N::f<int>();
29 N::f(); // expected-error {{no matching function}}
Richard Smith0e5d7b82013-07-25 23:08:39 +000030 // expected-note@Inputs/cxx-templates-b.h:6 {{couldn't infer template argument}}
31 // expected-note@Inputs/cxx-templates-b.h:7 {{requires single argument 't'}}
Richard Smithbf78e642013-06-24 22:51:00 +000032
33 template_param_kinds_1<0>(); // ok, from cxx-templates-a.h
34 template_param_kinds_1<int>(); // ok, from cxx-templates-b.h
35
36 template_param_kinds_2<Tmpl_T_C>(); // expected-error {{no matching function}}
Richard Smith5de91b52013-06-25 01:25:15 +000037 // expected-note@Inputs/cxx-templates-a.h:11 {{invalid explicitly-specified argument}}
38 // expected-note@Inputs/cxx-templates-b.h:11 {{invalid explicitly-specified argument}}
Richard Smithbf78e642013-06-24 22:51:00 +000039
40 template_param_kinds_2<Tmpl_T_I_I>(); // expected-error {{ambiguous}}
Richard Smith5de91b52013-06-25 01:25:15 +000041 // expected-note@Inputs/cxx-templates-a.h:11 {{candidate}}
42 // expected-note@Inputs/cxx-templates-b.h:11 {{candidate}}
Richard Smithbf78e642013-06-24 22:51:00 +000043
44 // FIXME: This should be valid, but we incorrectly match the template template
45 // argument against both template template parameters.
46 template_param_kinds_3<Tmpl_T_T_A>(); // expected-error {{ambiguous}}
Richard Smith5de91b52013-06-25 01:25:15 +000047 // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}}
48 // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}}
Richard Smithbf78e642013-06-24 22:51:00 +000049 template_param_kinds_3<Tmpl_T_T_B>(); // expected-error {{ambiguous}}
Richard Smith5de91b52013-06-25 01:25:15 +000050 // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}}
51 // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}}
Richard Smith0e5d7b82013-07-25 23:08:39 +000052
53 // Trigger the instantiation of a template in 'a' that uses a type defined in
54 // 'common'. That type is not visible here.
55 PerformDelayedLookup(defined_in_common);
56
Richard Smithb71782b2013-08-01 04:12:04 +000057 // Likewise, but via a default argument.
58 PerformDelayedLookupInDefaultArgument(defined_in_common);
59
Richard Smith0e5d7b82013-07-25 23:08:39 +000060 // Trigger the instantiation of a template in 'b' that uses a type defined in
61 // 'b_impl'. That type is not visible here.
62 UseDefinedInBImpl<int>();
63
64 // Trigger the instantiation of a template in 'a' that uses a type defined in
65 // 'b_impl', via a template defined in 'b'. Since the type is visible from
66 // within 'b', the instantiation succeeds.
67 UseDefinedInBImplIndirectly(defined_in_b_impl);
68
69 // Trigger the instantiation of a template in 'a' that uses a type defined in
70 // 'b_impl'. That type is not visible here, nor in 'a'. This fails; there is
71 // no reason why DefinedInBImpl should be visible here.
72 // expected-error@Inputs/cxx-templates-a.h:19 {{definition of 'DefinedInBImpl' must be imported}}
73 // expected-note@Inputs/cxx-templates-b-impl.h:1 {{definition is here}}
74 PerformDelayedLookup(defined_in_b_impl); // expected-note {{in instantiation of}}
Richard Smithd46d6de2013-10-13 23:50:45 +000075
76 merge_templates_a = merge_templates_b; // ok, same type
Richard Smith01a73372013-10-15 22:02:41 +000077
78 using T = decltype(enum_a_from_a);
79 using T = decltype(enum_b_from_b);
80 T e = true ? enum_a_from_a : enum_b_from_b;
81
82 UseRedeclaredEnum<int>(UseInt<1>());
83 // FIXME: Reintroduce this once we merge function template specializations.
84 //static_assert(UseRedeclaredEnumA == UseRedeclaredEnumB, "");
85 //static_assert(UseRedeclaredEnumA == UseRedeclaredEnum<int>, "");
86 //static_assert(UseRedeclaredEnumB == UseRedeclaredEnum<int>, "");
87 static_assert(enum_c_from_a == enum_c_from_b, "");
88 CommonTemplate<int> cti;
89 CommonTemplate<int>::E eee = CommonTemplate<int>::c;
Richard Smith8f8f05c2013-06-24 04:45:28 +000090}
91
Richard Smith7ecc31b2013-08-02 01:09:12 +000092RedeclaredAsFriend<int> raf1;
93RedeclareTemplateAsFriend<double> rtaf;
94RedeclaredAsFriend<double> raf2;
95
Richard Smith5de91b52013-06-25 01:25:15 +000096@import cxx_templates_common;
97
98typedef SomeTemplate<int*> SomeTemplateIntPtr;
99typedef SomeTemplate<int&> SomeTemplateIntRef;
100SomeTemplate<char*> some_template_char_ptr;
101SomeTemplate<char&> some_template_char_ref;
102
Richard Smithd55889a2013-09-09 16:55:27 +0000103void testImplicitSpecialMembers(SomeTemplate<char[1]> &a,
104 const SomeTemplate<char[1]> &b,
105 SomeTemplate<char[2]> &c,
106 const SomeTemplate<char[2]> &d) {
107 a = b;
108 c = d;
109}
110
Richard Smith8f8f05c2013-06-24 04:45:28 +0000111// CHECK-GLOBAL: DeclarationName 'f'
112// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
Richard Smith8f8f05c2013-06-24 04:45:28 +0000113// CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f'
114
Richard Smith8f8f05c2013-06-24 04:45:28 +0000115// CHECK-NAMESPACE-N: DeclarationName 'f'
116// CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
Richard Smith8f8f05c2013-06-24 04:45:28 +0000117// CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f'