| 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 |
| 29 |
module; |
| 30 |
extern int var; // expected-note {{previous declaration is here}} |
| 31 |
int func(); // expected-note {{previous declaration is here}} |
| 32 |
struct str; // expected-note {{previous declaration is here}} |
| 33 |
using type = int; |
| 34 |
|
| 35 |
template<typename> extern int var_tpl; // expected-note {{previous declaration is here}} |
| 36 |
template<typename> int func_tpl(); // expected-note {{previous declaration is here}} |
| 37 |
template<typename> struct str_tpl; // expected-note {{previous declaration is here}} |
| 38 |
template<typename> using type_tpl = int; // expected-note {{previous declaration is here}} |
| 39 |
|
| 40 |
typedef int type; |
| 41 |
namespace ns { using ::func; } |
| 42 |
namespace ns_alias = ns; |
| 43 |
#endif |
| 44 |
|
| 45 |
export module M; |
| 46 |
|
| 47 |
#ifdef USING |
| 48 |
using ::var; |
| 49 |
using ::func; |
| 50 |
using ::str; |
| 51 |
using ::type; |
| 52 |
using ::var_tpl; |
| 53 |
using ::func_tpl; |
| 54 |
using ::str_tpl; |
| 55 |
using ::type_tpl; |
| 56 |
#endif |
| 57 |
|
| 58 |
#ifdef EXPORT |
| 59 |
export { |
| 60 |
#endif |
| 61 |
|
| 62 |
extern int var; // expected-error {{declaration of 'var' in module M follows declaration in the global module}} |
| 63 |
int func(); // expected-error {{declaration of 'func' in module M follows declaration in the global module}} |
| 64 |
struct str; // expected-error {{declaration of 'str' in module M follows declaration in the global module}} |
| 65 |
using type = int; |
| 66 |
|
| 67 |
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module M follows declaration in the global module}} |
| 68 |
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module M follows declaration in the global module}} |
| 69 |
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module M follows declaration in the global module}} |
| 70 |
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module M follows declaration in the global module}} |
| 71 |
|
| 72 |
typedef int type; |
| 73 |
namespace ns { using ::func; } |
| 74 |
namespace ns_alias = ns; |
| 75 |
|
| 76 |
#ifdef EXPORT |
| 77 |
} |
| 78 |
#endif |
| 79 |
|
| 80 |
//--- module-vs-global.cpp |
| 81 |
import M; |
| 82 |
|
| 83 |
extern int var; // expected-error {{declaration of 'var' in the global module follows declaration in module M}} [email protected]:35 {{previous}} |
| 84 |
int func(); // expected-error {{declaration of 'func' in the global module follows declaration in module M}} [email protected]:36 {{previous}} |
| 85 |
struct str; // expected-error {{declaration of 'str' in the global module follows declaration in module M}} [email protected]:37 {{previous}} |
| 86 |
using type = int; |
| 87 |
|
| 88 |
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in the global module follows declaration in module M}} [email protected]:40 {{previous}} |
| 89 |
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in the global module follows declaration in module M}} [email protected]:41 {{previous}} |
| 90 |
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in the global module follows declaration in module M}} [email protected]:42 {{previous}} |
| 91 |
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in the global module follows declaration in module M}} [email protected]:43 {{previous}} |
| 92 |
|
| 93 |
typedef int type; |
| 94 |
namespace ns { using ::func; } |
| 95 |
namespace ns_alias = ns; |
| 96 |
|
| 97 |
//--- module-vs-module.cpp |
| 98 |
#ifdef MODULE_INTERFACE |
| 99 |
export module N; |
| 100 |
#else |
| 101 |
module N; |
| 102 |
#endif |
| 103 |
|
| 104 |
#ifndef NO_IMPORT |
| 105 |
import M; |
| 106 |
#endif |
| 107 |
|
| 108 |
#ifndef NO_ERRORS |
| 109 |
extern int var; // expected-error {{declaration of 'var' in module N follows declaration in module M}} [email protected]:35 {{previous}} |
| 110 |
int func(); // expected-error {{declaration of 'func' in module N follows declaration in module M}} [email protected]:36 {{previous}} |
| 111 |
struct str; // expected-error {{declaration of 'str' in module N follows declaration in module M}} [email protected]:37 {{previous}} |
| 112 |
using type = int; |
| 113 |
|
| 114 |
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module N follows declaration in module M}} [email protected]:40 {{previous}} |
| 115 |
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module N follows declaration in module M}} [email protected]:41 {{previous}} |
| 116 |
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module N follows declaration in module M}} [email protected]:42 {{previous}} |
| 117 |
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module N follows declaration in module M}} [email protected]:43 {{previous}} |
| 118 |
|
| 119 |
typedef int type; |
| 120 |
namespace ns { using ::func; } |
| 121 |
namespace ns_alias = ns; |
| 122 |
#endif |
| 123 |
|