1 // RUN: rm -rf %t
2 // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/submodules-merge-defs %s -verify -fno-modules-error-recovery -DTEXTUAL
3 // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/submodules-merge-defs %s -verify -fno-modules-error-recovery
4 // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/submodules-merge-defs %s -verify -fno-modules-error-recovery -fmodules-local-submodule-visibility -DTEXTUAL
5 // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/submodules-merge-defs %s -verify -fno-modules-error-recovery -fmodules-local-submodule-visibility
6 // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/submodules-merge-defs %s -verify -fno-modules-error-recovery -fmodules-local-submodule-visibility -DTEXTUAL -DEARLY_INDIRECT_INCLUDE
7 // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/submodules-merge-defs %s -verify -fno-modules-error-recovery -fmodules-local-submodule-visibility -fmodule-feature use_defs_twice -DIMPORT_USE_2
8 
9 // Trigger import of definitions, but don't make them visible.
10 #include "empty.h"
11 #ifdef EARLY_INDIRECT_INCLUDE
12 #include "indirect.h"
13 // expected-warning@defs.h:28 3{{anonymous non-C-compatible type}}
14 // expected-note@defs.h:28 6{{type is}}
15 #endif
16 
17 A pre_a;
18 // expected-error-re@-1 {{missing '#include "{{.*}}-defs.h"'; 'A' must be declared}}
19 // expected-note@defs.h:1 +{{here}}
20 extern class A pre_a2;
21 int pre_use_a = use_a(pre_a2); // expected-error 2{{'A' must be defined}} expected-error {{'use_a' must be declared}}
22 // expected-note@defs.h:2 +{{here}}
23 
24 B::Inner2 pre_bi; // expected-error +{{must be declared}} expected-error +{{must be defined}}
25 // expected-note@defs.h:4 +{{here}}
26 // expected-note@defs.h:17 +{{here}}
pre_bfi(B b)27 void pre_bfi(B b) { // expected-error +{{must be declared}}
28   b.f<int>();
29 }
30 
31 C_Base<1> pre_cb1; // expected-error +{{must be declared}} expected-error +{{must be defined}}
32 // expected-note@defs.h:23 +{{here}}
33 C1 pre_c1; // expected-error +{{must be declared}}
34 // expected-note@defs.h:25 +{{here}}
35 C2 pre_c2; // expected-error +{{must be declared}}
36 // expected-note@defs.h:26 +{{here}}
37 
38 D::X pre_dx; // expected-error +{{must be declared}} expected-error +{{must be defined}}
39 // expected-note@defs.h:28 +{{here}}
40 // expected-note@defs.h:29 +{{here}}
41 int pre_use_dx = use_dx(pre_dx); // ignored; pre_dx is invalid
42 
43 int pre_e = E(0); // expected-error {{must be declared}}
44 // expected-note@defs.h:32 +{{here}}
45 
46 int pre_ff = F<int>().f(); // expected-error +{{must be declared}}
47 int pre_fg = F<int>().g<int>(); // expected-error +{{must be declared}}
48 // expected-note@defs.h:34 +{{here}}
49 
50 G::A pre_ga // expected-error +{{must be declared}}
51   = G::a; // expected-error +{{must be declared}}
52 // expected-note@defs.h:49 +{{here}}
53 // expected-note@defs.h:50 +{{here}}
54 decltype(G::h) pre_gh = G::h; // expected-error +{{must be declared}} expected-error +{{must be defined}}
55 // expected-note@defs.h:51 +{{here}}
56 
57 int pre_h = H(); // expected-error +{{must be declared}}
58 // expected-note@defs.h:56 +{{here}}
59 using pre_i = I<>; // expected-error +{{must be declared}} expected-error +{{default argument of 'I' must be defined}}
60 // expected-note@defs.h:57 +{{here}}
61 
62 J<> pre_j; // expected-error {{'J' must be declared}}
63 // expected-error-re@-1 {{missing '#include "{{.*}}.h"'; default argument of 'J' must be defined before it is used}}
64 // expected-note@defs.h:58 +{{here}}
65 
66 ScopedEnum pre_scopedenum; // expected-error {{must be declared}}
67 // expected-note@defs.h:105 0-1{{here}}
68 // expected-note@defs.h:106 0-1{{here}}
69 enum ScopedEnum : int;
70 ScopedEnum pre_scopedenum_declared; // ok
71 
72 // Make definitions from second module visible.
73 #ifdef TEXTUAL
74 #include "import-and-redefine.h"
75 #elif defined IMPORT_USE_2
76 #include "use-defs-2.h"
77 #else
78 #include "merged-defs.h"
79 #endif
80 
81 A post_a;
82 int post_use_a = use_a(post_a);
83 B::Inner2 post_bi;
post_bfi(B b)84 void post_bfi(B b) {
85   b.f<int>();
86 }
87 C_Base<1> post_cb1;
88 C1 c1;
89 C2 c2;
90 D::X post_dx;
91 int post_use_dx = use_dx(post_dx);
92 int post_e = E(0);
93 int post_ff = F<char>().f();
94 int post_fg = F<char>().g<int>();
95 G::A post_ga = G::a;
96 decltype(G::h) post_gh = G::h;
97 int post_h = H();
98 using post_i = I<>;
99 J<> post_j;
100 template<typename T, int N, template<typename> class K> struct J;
101 J<> post_j2;
102 FriendDefArg::Y<int> friend_def_arg;
103 FriendDefArg::D<> friend_def_arg_d;
104 int post_anon_x_n = Anon::X().n;
105 
106 MergeFunctionTemplateSpecializations::X<int>::Q<char> xiqc;
107 
108 #ifdef TEXTUAL
109 #include "use-defs.h"
use_static_inline()110 void use_static_inline() { StaticInline::g({}); }
111 #ifdef EARLY_INDIRECT_INCLUDE
112 // expected-warning@-2 {{ambiguous use of internal linkage declaration 'g' defined in multiple modules}}
113 // expected-note@defs.h:71 {{declared here in module 'redef'}}
114 // expected-note@defs.h:71 {{declared here in module 'stuff.use'}}
115 #endif
116 int use_anon_enum = G::g;
117 #ifdef EARLY_INDIRECT_INCLUDE
118 // expected-warning@-2 3{{ambiguous use of internal linkage declaration 'g' defined in multiple modules}}
119 // FIXME: These notes are produced, but -verify can't match them?
120 // FIXME-note@defs.h:51 3{{declared here in module 'redef'}}
121 // FIXME-note@defs.h:51 3{{declared here in module 'stuff.use'}}
122 #endif
123 int use_named_enum = G::i;
124 #endif
125