| 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-export.cppm |
| 7 |
// RUN: %clang_cc1 -std=c++20 -verify %t/global-vs-module-using.cppm |
| 8 |
// |
| 9 |
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/M.cppm -o %t/M.pcm |
| 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-interface.cpp -fmodule-file=M=%t/M.pcm -verify |
| 16 |
// RUN: %clang_cc1 -std=c++20 %t/module-vs-module-interface.cpp -fmodule-file=M=%t/M.pcm -DNO_IMPORT |
| 17 |
// |
| 18 |
// RUN: %clang_cc1 -std=c++20 %t/module-vs-module-interface.cpp -fmodule-file=M=%t/M.pcm -emit-module-interface -o %t/N.pcm -DNO_ERRORS |
| 19 |
// RUN: %clang_cc1 -std=c++20 %t/module-vs-module-impl.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-impl.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-interface.cpp -fmodule-file=M=%t/M.pcm -emit-module-interface -o %t/N-no-M.pcm -DNO_ERRORS -DNO_IMPORT |
| 24 |
// RUN: %clang_cc1 -std=c++20 %t/module-vs-module-impl.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-impl.cpp -fmodule-file=N=%t/N-no-M.pcm -DNO_IMPORT |
| 26 |
|
| 27 |
//--- global-vs-module.cppm |
| 28 |
module; |
| 29 |
extern int var; // expected-note {{previous declaration is here}} |
| 30 |
int func(); // expected-note {{previous declaration is here}} |
| 31 |
struct str; // expected-note {{previous declaration is here}} |
| 32 |
using type = int; |
| 33 |
|
| 34 |
template<typename> extern int var_tpl; // expected-note {{previous declaration is here}} |
| 35 |
template<typename> int func_tpl(); // expected-note {{previous declaration is here}} |
| 36 |
template<typename> struct str_tpl; // expected-note {{previous declaration is here}} |
| 37 |
template<typename> using type_tpl = int; // expected-note {{previous declaration is here}} |
| 38 |
|
| 39 |
typedef int type; |
| 40 |
namespace ns { using ::func; } |
| 41 |
namespace ns_alias = ns; |
| 42 |
|
| 43 |
export module M; |
| 44 |
|
| 45 |
extern int var; // expected-error {{declaration of 'var' in module M follows declaration in the global module}} |
| 46 |
int func(); // expected-error {{declaration of 'func' in module M follows declaration in the global module}} |
| 47 |
struct str; // expected-error {{declaration of 'str' in module M follows declaration in the global module}} |
| 48 |
using type = int; |
| 49 |
|
| 50 |
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module M follows declaration in the global module}} |
| 51 |
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module M follows declaration in the global module}} |
| 52 |
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module M follows declaration in the global module}} |
| 53 |
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module M follows declaration in the global module}} |
| 54 |
|
| 55 |
typedef int type; |
| 56 |
namespace ns { using ::func; } |
| 57 |
namespace ns_alias = ns; |
| 58 |
|
| 59 |
//--- global-vs-module-export.cppm |
| 60 |
module; |
| 61 |
extern int var; // expected-note {{previous declaration is here}} |
| 62 |
int func(); // expected-note {{previous declaration is here}} |
| 63 |
struct str; // expected-note {{previous declaration is here}} |
| 64 |
using type = int; |
| 65 |
|
| 66 |
template<typename> extern int var_tpl; // expected-note {{previous declaration is here}} |
| 67 |
template<typename> int func_tpl(); // expected-note {{previous declaration is here}} |
| 68 |
template<typename> struct str_tpl; // expected-note {{previous declaration is here}} |
| 69 |
template<typename> using type_tpl = int; // expected-note {{previous declaration is here}} |
| 70 |
|
| 71 |
typedef int type; |
| 72 |
namespace ns { using ::func; } |
| 73 |
namespace ns_alias = ns; |
| 74 |
|
| 75 |
export module M; |
| 76 |
|
| 77 |
export { |
| 78 |
extern int var; // expected-error {{declaration of 'var' in module M follows declaration in the global module}} |
| 79 |
int func(); // expected-error {{declaration of 'func' in module M follows declaration in the global module}} |
| 80 |
struct str; // expected-error {{declaration of 'str' in module M follows declaration in the global module}} |
| 81 |
using type = int; |
| 82 |
|
| 83 |
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module M follows declaration in the global module}} |
| 84 |
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module M follows declaration in the global module}} |
| 85 |
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module M follows declaration in the global module}} |
| 86 |
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module M follows declaration in the global module}} |
| 87 |
|
| 88 |
typedef int type; |
| 89 |
namespace ns { using ::func; } |
| 90 |
namespace ns_alias = ns; |
| 91 |
} |
| 92 |
|
| 93 |
//--- global-vs-module-using.cppm |
| 94 |
module; |
| 95 |
extern int var; // expected-note {{previous declaration is here}} |
| 96 |
int func(); // expected-note {{previous declaration is here}} |
| 97 |
struct str; // expected-note {{previous declaration is here}} |
| 98 |
using type = int; |
| 99 |
|
| 100 |
template<typename> extern int var_tpl; // expected-note {{previous declaration is here}} |
| 101 |
template<typename> int func_tpl(); // expected-note {{previous declaration is here}} |
| 102 |
template<typename> struct str_tpl; // expected-note {{previous declaration is here}} |
| 103 |
template<typename> using type_tpl = int; // expected-note {{previous declaration is here}} |
| 104 |
|
| 105 |
typedef int type; |
| 106 |
namespace ns { using ::func; } |
| 107 |
namespace ns_alias = ns; |
| 108 |
|
| 109 |
export module M; |
| 110 |
|
| 111 |
using ::var; |
| 112 |
using ::func; |
| 113 |
using ::str; |
| 114 |
using ::type; |
| 115 |
using ::var_tpl; |
| 116 |
using ::func_tpl; |
| 117 |
using ::str_tpl; |
| 118 |
using ::type_tpl; |
| 119 |
|
| 120 |
extern int var; // expected-error {{declaration of 'var' in module M follows declaration in the global module}} |
| 121 |
int func(); // expected-error {{declaration of 'func' in module M follows declaration in the global module}} |
| 122 |
struct str; // expected-error {{declaration of 'str' in module M follows declaration in the global module}} |
| 123 |
using type = int; |
| 124 |
|
| 125 |
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module M follows declaration in the global module}} |
| 126 |
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module M follows declaration in the global module}} |
| 127 |
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module M follows declaration in the global module}} |
| 128 |
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module M follows declaration in the global module}} |
| 129 |
|
| 130 |
typedef int type; |
| 131 |
namespace ns { using ::func; } |
| 132 |
namespace ns_alias = ns; |
| 133 |
|
| 134 |
//--- M.cppm |
| 135 |
export module M; |
| 136 |
|
| 137 |
export { |
| 138 |
extern int var; // expected-error {{declaration of 'var' in module M follows declaration in the global module}} |
| 139 |
int func(); // expected-error {{declaration of 'func' in module M follows declaration in the global module}} |
| 140 |
struct str; // expected-error {{declaration of 'str' in module M follows declaration in the global module}} |
| 141 |
using type = int; |
| 142 |
|
| 143 |
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module M follows declaration in the global module}} |
| 144 |
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module M follows declaration in the global module}} |
| 145 |
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module M follows declaration in the global module}} |
| 146 |
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module M follows declaration in the global module}} |
| 147 |
|
| 148 |
typedef int type; |
| 149 |
namespace ns { using ::func; } |
| 150 |
namespace ns_alias = ns; |
| 151 |
} |
| 152 |
|
| 153 |
//--- module-vs-global.cpp |
| 154 |
module; |
| 155 |
import M; |
| 156 |
|
| 157 |
extern int var; // expected-error {{declaration of 'var' in the global module follows declaration in module M}} [email protected]:4 {{previous}} |
| 158 |
int func(); // expected-error {{declaration of 'func' in the global module follows declaration in module M}} [email protected]:5 {{previous}} |
| 159 |
struct str; // expected-error {{declaration of 'str' in the global module follows declaration in module M}} [email protected]:6 {{previous}} |
| 160 |
using type = int; |
| 161 |
|
| 162 |
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in the global module follows declaration in module M}} [email protected]:9 {{previous}} |
| 163 |
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in the global module follows declaration in module M}} [email protected]:10 {{previous}} |
| 164 |
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in the global module follows declaration in module M}} [email protected]:11 {{previous}} |
| 165 |
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in the global module follows declaration in module M}} [email protected]:12 {{previous}} |
| 166 |
|
| 167 |
typedef int type; |
| 168 |
namespace ns { using ::func; } |
| 169 |
namespace ns_alias = ns; |
| 170 |
|
| 171 |
export module N; |
| 172 |
|
| 173 |
//--- module-vs-module-interface.cpp |
| 174 |
export module N; |
| 175 |
|
| 176 |
#ifndef NO_IMPORT |
| 177 |
import M; |
| 178 |
#endif |
| 179 |
|
| 180 |
#ifndef NO_ERRORS |
| 181 |
extern int var; // expected-error {{declaration of 'var' in module N follows declaration in module M}} [email protected]:4 {{previous}} |
| 182 |
int func(); // expected-error {{declaration of 'func' in module N follows declaration in module M}} [email protected]:5 {{previous}} |
| 183 |
struct str; // expected-error {{declaration of 'str' in module N follows declaration in module M}} [email protected]:6 {{previous}} |
| 184 |
using type = int; |
| 185 |
|
| 186 |
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module N follows declaration in module M}} [email protected]:9 {{previous}} |
| 187 |
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module N follows declaration in module M}} [email protected]:10 {{previous}} |
| 188 |
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module N follows declaration in module M}} [email protected]:11 {{previous}} |
| 189 |
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module N follows declaration in module M}} [email protected]:12 {{previous}} |
| 190 |
|
| 191 |
typedef int type; |
| 192 |
namespace ns { using ::func; } |
| 193 |
namespace ns_alias = ns; |
| 194 |
#endif |
| 195 |
|
| 196 |
//--- module-vs-module-impl.cpp |
| 197 |
module N; |
| 198 |
|
| 199 |
#ifndef NO_IMPORT |
| 200 |
import M; |
| 201 |
#endif |
| 202 |
|
| 203 |
#ifndef NO_ERRORS |
| 204 |
extern int var; // expected-error {{declaration of 'var' in module N follows declaration in module M}} [email protected]:4 {{previous}} |
| 205 |
int func(); // expected-error {{declaration of 'func' in module N follows declaration in module M}} [email protected]:5 {{previous}} |
| 206 |
struct str; // expected-error {{declaration of 'str' in module N follows declaration in module M}} [email protected]:6 {{previous}} |
| 207 |
using type = int; |
| 208 |
|
| 209 |
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module N follows declaration in module M}} [email protected]:9 {{previous}} |
| 210 |
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module N follows declaration in module M}} [email protected]:10 {{previous}} |
| 211 |
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module N follows declaration in module M}} [email protected]:11 {{previous}} |
| 212 |
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module N follows declaration in module M}} [email protected]:12 {{previous}} |
| 213 |
|
| 214 |
typedef int type; |
| 215 |
namespace ns { using ::func; } |
| 216 |
namespace ns_alias = ns; |
| 217 |
#endif |