xref: /aosp_15_r20/external/clang/test/Modules/redecl-add-after-load.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: rm -rf %t
2*67e74705SXin Li // RUN: %clang_cc1 -x objective-c++ -fmodules -fimplicit-module-maps -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11
3*67e74705SXin Li // RUN: %clang_cc1 -x objective-c++ -fmodules -fimplicit-module-maps -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11 -DIMPORT_DECLS
4*67e74705SXin Li 
5*67e74705SXin Li // expected-no-diagnostics
6*67e74705SXin Li 
7*67e74705SXin Li #ifdef IMPORT_DECLS
8*67e74705SXin Li @import redecl_add_after_load_decls;
9*67e74705SXin Li #else
10*67e74705SXin Li typedef struct A B;
11*67e74705SXin Li extern const int variable;
12*67e74705SXin Li extern constexpr int function();
test(bool b)13*67e74705SXin Li constexpr int test(bool b) { return b ? variable : function(); }
14*67e74705SXin Li 
15*67e74705SXin Li namespace N {
16*67e74705SXin Li   typedef struct A B;
17*67e74705SXin Li   extern const int variable;
18*67e74705SXin Li   extern constexpr int function();
19*67e74705SXin Li }
20*67e74705SXin Li typedef N::B NB;
N_test(bool b)21*67e74705SXin Li constexpr int N_test(bool b) { return b ? N::variable : N::function(); }
22*67e74705SXin Li 
23*67e74705SXin Li @import redecl_add_after_load_top;
24*67e74705SXin Li typedef C::A CB;
C_test(bool b)25*67e74705SXin Li constexpr int C_test(bool b) { return b ? C::variable : C::function(); }
26*67e74705SXin Li 
27*67e74705SXin Li struct D {
28*67e74705SXin Li   struct A;
29*67e74705SXin Li   static const int variable;
30*67e74705SXin Li   static constexpr int function();
31*67e74705SXin Li };
32*67e74705SXin Li typedef D::A DB;
D_test(bool b)33*67e74705SXin Li constexpr int D_test(bool b) { return b ? D::variable : D::function(); }
34*67e74705SXin Li #endif
35*67e74705SXin Li 
36*67e74705SXin Li @import redecl_add_after_load;
37*67e74705SXin Li 
38*67e74705SXin Li B tu_struct_test;
39*67e74705SXin Li constexpr int tu_variable_test = test(true);
40*67e74705SXin Li constexpr int tu_function_test = test(false);
41*67e74705SXin Li 
42*67e74705SXin Li NB ns_struct_test;
43*67e74705SXin Li constexpr int ns_variable_test = N_test(true);
44*67e74705SXin Li constexpr int ns_function_test = N_test(false);
45*67e74705SXin Li 
46*67e74705SXin Li CB struct_struct_test;
47*67e74705SXin Li constexpr int struct_variable_test = C_test(true);
48*67e74705SXin Li constexpr int struct_function_test = C_test(false);
49*67e74705SXin Li 
50*67e74705SXin Li DB merged_struct_struct_test;
51*67e74705SXin Li constexpr int merged_struct_variable_test = D_test(true);
52*67e74705SXin Li constexpr int merged_struct_function_test = D_test(false);
53