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
9 template<typename, char> struct Tmpl_T_C {};
10 template<typename, int, int> struct Tmpl_T_I_I {};
11
12 template<typename A, typename B, A> struct Tmpl_T_T_A {};
13 template<typename A, typename B, B> struct Tmpl_T_T_B {};
14
g()15 void g() {
16 f(0);
17 f<double>(1.0);
18 f<int>();
19 f(); // expected-error {{no matching function}}
20 // expected-note@Inputs/cxx-templates-b.h:3 {{couldn't infer template argument}}
21 // expected-note@Inputs/cxx-templates-b.h:4 {{requires single argument}}
22
23 N::f(0);
24 N::f<double>(1.0);
25 N::f<int>();
26 N::f(); // expected-error {{no matching function}}
27 // expected-note@Inputs/cxx-templates-b.h:6 {{couldn't infer template argument}}
28 // expected-note@Inputs/cxx-templates-b.h:7 {{requires single argument 't'}}
29
30 template_param_kinds_1<0>(); // ok, from cxx-templates-a.h
31 template_param_kinds_1<int>(); // ok, from cxx-templates-b.h
32
33 template_param_kinds_2<Tmpl_T_C>(); // expected-error {{no matching function}}
34 // expected-note@Inputs/cxx-templates-a.h:11 {{invalid explicitly-specified argument}}
35 // expected-note@Inputs/cxx-templates-b.h:11 {{invalid explicitly-specified argument}}
36
37 template_param_kinds_2<Tmpl_T_I_I>(); // expected-error {{ambiguous}}
38 // expected-note@Inputs/cxx-templates-a.h:11 {{candidate}}
39 // expected-note@Inputs/cxx-templates-b.h:11 {{candidate}}
40
41 // FIXME: This should be valid, but we incorrectly match the template template
42 // argument against both template template parameters.
43 template_param_kinds_3<Tmpl_T_T_A>(); // expected-error {{ambiguous}}
44 // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}}
45 // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}}
46 template_param_kinds_3<Tmpl_T_T_B>(); // expected-error {{ambiguous}}
47 // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}}
48 // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}}
49
50 // Trigger the instantiation of a template in 'a' that uses a type defined in
51 // 'common'. That type is not visible here.
52 PerformDelayedLookup(defined_in_common);
53
54 // Likewise, but via a default argument.
55 PerformDelayedLookupInDefaultArgument(defined_in_common);
56
57 // Trigger the instantiation of a template in 'b' that uses a type defined in
58 // 'b_impl'. That type is not visible here.
59 UseDefinedInBImpl<int>();
60
61 // Trigger the instantiation of a template in 'a' that uses a type defined in
62 // 'b_impl', via a template defined in 'b'. Since the type is visible from
63 // within 'b', the instantiation succeeds.
64 UseDefinedInBImplIndirectly(defined_in_b_impl);
65
66 // Trigger the instantiation of a template in 'a' that uses a type defined in
67 // 'b_impl'. That type is not visible here, nor in 'a'. This fails; there is
68 // no reason why DefinedInBImpl should be visible here.
69 // expected-error@Inputs/cxx-templates-a.h:19 {{definition of 'DefinedInBImpl' must be imported}}
70 // expected-note@Inputs/cxx-templates-b-impl.h:1 {{definition is here}}
71 PerformDelayedLookup(defined_in_b_impl); // expected-note {{in instantiation of}}
72 }
73
74 RedeclaredAsFriend<int> raf1;
75 RedeclareTemplateAsFriend<double> rtaf;
76 RedeclaredAsFriend<double> raf2;
77
78 @import cxx_templates_common;
79
80 typedef SomeTemplate<int*> SomeTemplateIntPtr;
81 typedef SomeTemplate<int&> SomeTemplateIntRef;
82 SomeTemplate<char*> some_template_char_ptr;
83 SomeTemplate<char&> some_template_char_ref;
84
85 // FIXME: There should only be two 'f's here.
86 // CHECK-GLOBAL: DeclarationName 'f'
87 // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
88 // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
89 // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
90 // CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f'
91
92 // CHECK-NAMESPACE-N: DeclarationName 'f'
93 // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
94 // CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f'
95