xref: /llvm-project/clang/test/CXX/module/basic/basic.def.odr/p6.cppm (revision b37233a253f30e4bd5f040d598826df443293bee)
1// RUN: rm -rf %t
2// RUN: mkdir %t
3// RUN: split-file %s %t
4//
5// RUN: %clang_cc1 -std=c++20 -verify %t/global-vs-module.cppm
6// RUN: %clang_cc1 -std=c++20 -verify %t/global-vs-module.cppm -DEXPORT
7// RUN: %clang_cc1 -std=c++20 -verify %t/global-vs-module.cppm -DUSING
8//
9// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/global-vs-module.cppm -o %t/M.pcm -DNO_GLOBAL -DEXPORT
10// RUN: %clang_cc1 -std=c++20 -verify %t/module-vs-global.cpp -fmodule-file=M=%t/M.pcm
11//
12// Some of the following tests intentionally have no -verify in their RUN
13// lines; we are testing that those cases do not produce errors.
14//
15// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=M=%t/M.pcm -DMODULE_INTERFACE -verify
16// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=M=%t/M.pcm -DMODULE_INTERFACE -DNO_IMPORT
17//
18// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=M=%t/M.pcm -emit-module-interface -o %t/N.pcm -DMODULE_INTERFACE -DNO_ERRORS
19// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=M=%t/M.pcm -fmodule-file=N=%t/N.pcm -verify
20//
21// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=M=%t/M.pcm -fmodule-file=N=%t/N.pcm -DNO_IMPORT -verify
22//
23// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=M=%t/M.pcm -emit-module-interface -o %t/N-no-M.pcm -DMODULE_INTERFACE -DNO_ERRORS -DNO_IMPORT
24// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=M=%t/M.pcm -fmodule-file=N=%t/N-no-M.pcm -verify
25// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=N=%t/N-no-M.pcm -DNO_IMPORT
26
27//--- global-vs-module.cppm
28#ifndef NO_GLOBAL
29module;
30extern int var; // expected-note {{previous declaration is here}}
31int func(); // expected-note {{previous declaration is here}}
32struct str; // expected-note {{previous declaration is here}}
33using type = int;
34
35template<typename> extern int var_tpl; // expected-note {{previous declaration is here}}
36template<typename> int func_tpl(); // expected-note {{previous declaration is here}}
37template<typename> struct str_tpl; // expected-note {{previous declaration is here}}
38template<typename> using type_tpl = int; // expected-note {{previous declaration is here}}
39
40typedef int type;
41namespace ns { using ::func; }
42namespace ns_alias = ns;
43#endif
44
45export module M;
46
47#ifdef USING
48using ::var;
49using ::func;
50using ::str;
51using ::type;
52using ::var_tpl;
53using ::func_tpl;
54using ::str_tpl;
55using ::type_tpl;
56#endif
57
58#ifdef EXPORT
59export {
60#endif
61
62extern int var; // expected-error {{declaration of 'var' in module M follows declaration in the global module}}
63int func(); // expected-error {{declaration of 'func' in module M follows declaration in the global module}}
64struct str; // expected-error {{declaration of 'str' in module M follows declaration in the global module}}
65using type = int;
66
67template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module M follows declaration in the global module}}
68template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module M follows declaration in the global module}}
69template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module M follows declaration in the global module}}
70template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module M follows declaration in the global module}}
71
72typedef int type;
73namespace ns { using ::func; }
74namespace ns_alias = ns;
75
76#ifdef EXPORT
77}
78#endif
79
80//--- module-vs-global.cpp
81import M;
82
83extern int var; // expected-error {{declaration of 'var' in the global module follows declaration in module M}} expected-note@global-vs-module.cppm:35 {{previous}}
84int func(); // expected-error {{declaration of 'func' in the global module follows declaration in module M}} expected-note@global-vs-module.cppm:36 {{previous}}
85struct str; // expected-error {{declaration of 'str' in the global module follows declaration in module M}} expected-note@global-vs-module.cppm:37 {{previous}}
86using type = int;
87
88template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cppm:40 {{previous}}
89template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cppm:41 {{previous}}
90template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cppm:42 {{previous}}
91template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cppm:43 {{previous}}
92
93typedef int type;
94namespace ns { using ::func; }
95namespace ns_alias = ns;
96
97//--- module-vs-module.cpp
98#ifdef MODULE_INTERFACE
99export module N;
100#else
101module N;
102#endif
103
104#ifndef NO_IMPORT
105import M;
106#endif
107
108#ifndef NO_ERRORS
109extern int var; // expected-error {{declaration of 'var' in module N follows declaration in module M}} expected-note@global-vs-module.cppm:35 {{previous}}
110int func(); // expected-error {{declaration of 'func' in module N follows declaration in module M}} expected-note@global-vs-module.cppm:36 {{previous}}
111struct str; // expected-error {{declaration of 'str' in module N follows declaration in module M}} expected-note@global-vs-module.cppm:37 {{previous}}
112using type = int;
113
114template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cppm:40 {{previous}}
115template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cppm:41 {{previous}}
116template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cppm:42 {{previous}}
117template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cppm:43 {{previous}}
118
119typedef int type;
120namespace ns { using ::func; }
121namespace ns_alias = ns;
122#endif
123
124