blob: c173d670802f6a2128457fca73d65a52677eb7b1 [file] [log] [blame]
Richard Smith8f8f05c2013-06-24 04:45:28 +00001// RUN: rm -rf %t
Richard Smith35f986d2014-08-11 22:11:07 +00002// 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
Richard Smith3d23c422014-05-07 02:25:43 +00004// 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
Richard Smith8f8f05c2013-06-24 04:45:28 +00006
7@import cxx_templates_a;
8@import cxx_templates_b;
Richard Smith0c1065f2013-10-15 23:19:58 +00009@import cxx_templates_c;
Richard Smith01a73372013-10-15 22:02:41 +000010@import cxx_templates_common;
Richard Smith8f8f05c2013-06-24 04:45:28 +000011
Richard Smithbf78e642013-06-24 22:51:00 +000012template<typename, char> struct Tmpl_T_C {};
13template<typename, int, int> struct Tmpl_T_I_I {};
14
15template<typename A, typename B, A> struct Tmpl_T_T_A {};
16template<typename A, typename B, B> struct Tmpl_T_T_B {};
17
Richard Smith01a73372013-10-15 22:02:41 +000018template<int> struct UseInt {};
19
Richard Smith8f8f05c2013-06-24 04:45:28 +000020void g() {
21 f(0);
22 f<double>(1.0);
23 f<int>();
24 f(); // expected-error {{no matching function}}
Richard Smith5de91b52013-06-25 01:25:15 +000025 // 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}}
Richard Smith8f8f05c2013-06-24 04:45:28 +000027
28 N::f(0);
29 N::f<double>(1.0);
30 N::f<int>();
31 N::f(); // expected-error {{no matching function}}
Richard Smithbb853c72014-08-13 01:23:33 +000032 // expected-note@Inputs/cxx-templates-b.h:6 {{couldn't infer template argument}}
33 // expected-note@Inputs/cxx-templates-b.h:7 {{requires single argument}}
Richard Smithbf78e642013-06-24 22:51:00 +000034
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}}
Richard Smith5de91b52013-06-25 01:25:15 +000039 // 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}}
Richard Smithbf78e642013-06-24 22:51:00 +000041
42 template_param_kinds_2<Tmpl_T_I_I>(); // expected-error {{ambiguous}}
Richard Smith5de91b52013-06-25 01:25:15 +000043 // expected-note@Inputs/cxx-templates-a.h:11 {{candidate}}
44 // expected-note@Inputs/cxx-templates-b.h:11 {{candidate}}
Richard Smithbf78e642013-06-24 22:51:00 +000045
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}}
Richard Smith5de91b52013-06-25 01:25:15 +000049 // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}}
50 // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}}
Richard Smithbf78e642013-06-24 22:51:00 +000051 template_param_kinds_3<Tmpl_T_T_B>(); // expected-error {{ambiguous}}
Richard Smith5de91b52013-06-25 01:25:15 +000052 // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}}
53 // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}}
Richard Smith0e5d7b82013-07-25 23:08:39 +000054
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
Richard Smithb71782b2013-08-01 04:12:04 +000059 // Likewise, but via a default argument.
60 PerformDelayedLookupInDefaultArgument(defined_in_common);
61
Richard Smith0e5d7b82013-07-25 23:08:39 +000062 // 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.
Richard Smith3d23c422014-05-07 02:25:43 +000074 //
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 //
Richard Smith0e5d7b82013-07-25 23:08:39 +000079 // expected-error@Inputs/cxx-templates-a.h:19 {{definition of 'DefinedInBImpl' must be imported}}
Richard Smith3d23c422014-05-07 02:25:43 +000080 // 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 +{{}}
Richard Smith0e5d7b82013-07-25 23:08:39 +000083 PerformDelayedLookup(defined_in_b_impl); // expected-note {{in instantiation of}}
Richard Smithd46d6de2013-10-13 23:50:45 +000084
85 merge_templates_a = merge_templates_b; // ok, same type
Richard Smith01a73372013-10-15 22:02:41 +000086
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;
Richard Smith3d23c422014-05-07 02:25:43 +000099
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;
Richard Smithdf352052014-05-22 20:59:29 +0000105
106 int &p = WithPartialSpecializationUse().f();
Richard Smith871cd4c2014-05-23 21:00:28 +0000107 int &q = WithExplicitSpecializationUse().inner_template<int>();
Richard Smith049fcd82014-07-29 00:58:01 +0000108 int *r = PartiallyInstantiatePartialSpec<int*>::bar();
Richard Smith8c913ec2014-08-14 02:21:01 +0000109
110 (void)&WithImplicitSpecialMembers<int>::n;
Richard Smith8f8f05c2013-06-24 04:45:28 +0000111}
112
Richard Smithdc5523d2014-07-11 00:20:06 +0000113static_assert(Outer<int>::Inner<int>::f() == 1, "");
114static_assert(Outer<int>::Inner<int>::g() == 2, "");
115
Richard Smith547864d2014-07-11 18:22:58 +0000116static_assert(MergeTemplateDefinitions<int>::f() == 1, "");
117static_assert(MergeTemplateDefinitions<int>::g() == 2, "");
118
Richard Smith7ecc31b2013-08-02 01:09:12 +0000119RedeclaredAsFriend<int> raf1;
120RedeclareTemplateAsFriend<double> rtaf;
121RedeclaredAsFriend<double> raf2;
122
Richard Smith0c1065f2013-10-15 23:19:58 +0000123MergeSpecializations<int*>::partially_specialized_in_a spec_in_a_1;
124MergeSpecializations<int&>::partially_specialized_in_b spec_in_b_1;
125MergeSpecializations<int[]>::partially_specialized_in_c spec_in_c_1;
126MergeSpecializations<char>::explicitly_specialized_in_a spec_in_a_2;
127MergeSpecializations<double>::explicitly_specialized_in_b spec_in_b_2;
128MergeSpecializations<bool>::explicitly_specialized_in_c spec_in_c_2;
129
Richard Smith5de91b52013-06-25 01:25:15 +0000130@import cxx_templates_common;
131
132typedef SomeTemplate<int*> SomeTemplateIntPtr;
133typedef SomeTemplate<int&> SomeTemplateIntRef;
134SomeTemplate<char*> some_template_char_ptr;
135SomeTemplate<char&> some_template_char_ref;
136
Richard Smithd55889a2013-09-09 16:55:27 +0000137void testImplicitSpecialMembers(SomeTemplate<char[1]> &a,
138 const SomeTemplate<char[1]> &b,
139 SomeTemplate<char[2]> &c,
140 const SomeTemplate<char[2]> &d) {
141 a = b;
142 c = d;
143}
144
Richard Smithc264d352014-03-23 02:30:01 +0000145bool testFriendInClassTemplate(Std::WithFriend<int> wfi) {
146 return wfi != wfi;
147}
148
Richard Smith561e0dc2014-03-23 19:45:26 +0000149namespace Std {
150 void g(); // expected-error {{functions that differ only in their return type cannot be overloaded}}
151 // expected-note@cxx-templates-common.h:21 {{previous}}
152}
153
Richard Smith8f8f05c2013-06-24 04:45:28 +0000154// CHECK-GLOBAL: DeclarationName 'f'
155// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
Richard Smith8f8f05c2013-06-24 04:45:28 +0000156// CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f'
157
Richard Smith8f8f05c2013-06-24 04:45:28 +0000158// CHECK-NAMESPACE-N: DeclarationName 'f'
159// CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
Richard Smith8f8f05c2013-06-24 04:45:28 +0000160// CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f'
Richard Smithcbdf7332014-03-18 02:07:28 +0000161
David Blaikie5ee3d002014-04-02 05:48:29 +0000162// CHECK-DUMP: ClassTemplateDecl {{.*}} <{{.*[/\\]}}cxx-templates-common.h:1:1, {{.*}}> col:{{.*}} in cxx_templates_common SomeTemplate
Richard Smithcbdf7332014-03-18 02:07:28 +0000163// CHECK-DUMP: ClassTemplateSpecializationDecl {{.*}} prev [[CHAR2:[^ ]*]] {{.*}} SomeTemplate
164// CHECK-DUMP-NEXT: TemplateArgument type 'char [2]'
165// CHECK-DUMP: ClassTemplateSpecializationDecl [[CHAR2]] {{.*}} SomeTemplate definition
166// CHECK-DUMP-NEXT: TemplateArgument type 'char [2]'
167// CHECK-DUMP: ClassTemplateSpecializationDecl {{.*}} prev [[CHAR1:[^ ]*]] {{.*}} SomeTemplate
168// CHECK-DUMP-NEXT: TemplateArgument type 'char [1]'
169// CHECK-DUMP: ClassTemplateSpecializationDecl [[CHAR1]] {{.*}} SomeTemplate definition
170// CHECK-DUMP-NEXT: TemplateArgument type 'char [1]'