[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / submodules-merge-defs.cpp
blob0a54699a9672366ec660c4bba035656a3d498d41
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
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
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}}
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}}
27 void pre_bfi(B b) { // expected-error +{{must be declared}}
28 b.f<int>();
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}}
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
43 int pre_e = E(0); // expected-error {{must be declared}}
44 // expected-note@defs.h:32 +{{here}}
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}}
50 G::A pre_ga // expected-error +{{must be declared}}
51 = G::a; // expected-error +{{must be declared}}
52 // expected-note@defs.h:50 +{{here}}
53 decltype(G::h) pre_gh = G::h; // expected-error +{{must be declared}} expected-error +{{must be defined}}
54 // expected-note@defs.h:51 +{{here}}
56 int pre_h = H(); // expected-error +{{must be declared}}
57 // expected-note@defs.h:56 +{{here}}
58 using pre_i = I<>; // expected-error +{{must be declared}} expected-error +{{default argument of 'I' must be defined}}
59 // expected-note@defs.h:57 +{{here}}
61 J<> pre_j; // expected-error {{'J' must be declared}}
62 // expected-error-re@-1 {{missing '#include "{{.*}}.h"'; default argument of 'J' must be defined before it is used}}
63 // expected-note@defs.h:58 +{{here}}
65 ScopedEnum pre_scopedenum; // expected-error {{must be declared}}
66 // expected-note@defs.h:105 0-1{{here}}
67 // expected-note@defs.h:106 0-1{{here}}
68 enum ScopedEnum : int;
69 ScopedEnum pre_scopedenum_declared; // ok
71 // Make definitions from second module visible.
72 #ifdef TEXTUAL
73 #include "import-and-redefine.h"
74 #elif defined IMPORT_USE_2
75 #include "use-defs-2.h"
76 #else
77 #include "merged-defs.h"
78 #endif
80 A post_a;
81 int post_use_a = use_a(post_a);
82 B::Inner2 post_bi;
83 void post_bfi(B b) {
84 b.f<int>();
86 C_Base<1> post_cb1;
87 C1 c1;
88 C2 c2;
89 D::X post_dx;
90 int post_use_dx = use_dx(post_dx);
91 int post_e = E(0);
92 int post_ff = F<char>().f();
93 int post_fg = F<char>().g<int>();
94 G::A post_ga = G::a;
95 decltype(G::h) post_gh = G::h;
96 int post_h = H();
97 using post_i = I<>;
98 J<> post_j;
99 template<typename T, int N, template<typename> class K> struct J;
100 J<> post_j2;
101 FriendDefArg::Y<int> friend_def_arg;
102 FriendDefArg::D<> friend_def_arg_d;
103 int post_anon_x_n = Anon::X().n;
105 MergeFunctionTemplateSpecializations::X<int>::Q<char> xiqc;
107 #ifdef TEXTUAL
108 #include "use-defs.h"
109 void use_static_inline() { StaticInline::g({}); }
110 #ifdef EARLY_INDIRECT_INCLUDE
111 // expected-warning@-2 {{ambiguous use of internal linkage declaration 'g' defined in multiple modules}}
112 // expected-note@defs.h:71 {{declared here in module 'redef'}}
113 // expected-note@defs.h:71 {{declared here in module 'stuff.use'}}
114 #endif
115 int use_anon_enum = G::g;
116 #ifdef EARLY_INDIRECT_INCLUDE
117 // expected-warning@-2 3{{ambiguous use of internal linkage declaration 'g' defined in multiple modules}}
118 // FIXME: These notes are produced, but -verify can't match them?
119 // FIXME-note@defs.h:51 3{{declared here in module 'redef'}}
120 // FIXME-note@defs.h:51 3{{declared here in module 'stuff.use'}}
121 #endif
122 int use_named_enum = G::i;
123 #endif