Clang Project

clang_source_code/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp
1// RUN: %clang_cc1 -fmodules-ts -verify -std=c++17 %s 
2// RUN: %clang_cc1 -fmodules-ts -verify -std=c++17 %s -DEXPORT
3// RUN: %clang_cc1 -fmodules-ts -verify -std=c++17 %s -DUSING
4
5#ifndef NO_GLOBAL
6extern int var; // expected-note {{previous declaration is here}}
7int func(); // expected-note {{previous declaration is here}}
8struct str; // expected-note {{previous declaration is here}}
9using type = int;
10
11template<typename> extern int var_tpl; // expected-note {{previous declaration is here}}
12template<typename> int func_tpl(); // expected-note-re {{{{previous declaration is here|target of using declaration}}}}
13template<typename> struct str_tpl; // expected-note {{previous declaration is here}}
14template<typename> using type_tpl = int; // expected-note {{previous declaration is here}}
15
16typedef int type;
17namespace ns { using ::func; }
18namespace ns_alias = ns;
19#endif
20
21export module M;
22
23#ifdef USING
24using ::var;
25using ::func;
26using ::str;
27using ::type;
28using ::var_tpl;
29using ::func_tpl; // expected-note {{using declaration}}
30using ::str_tpl;
31using ::type_tpl;
32#endif
33
34#ifdef EXPORT
35export {
36#endif
37
38extern int var; // expected-error {{declaration of 'var' in module M follows declaration in the global module}}
39int func(); // expected-error {{declaration of 'func' in module M follows declaration in the global module}}
40struct str; // expected-error {{declaration of 'str' in module M follows declaration in the global module}}
41using type = int;
42
43template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module M follows declaration in the global module}}
44// FIXME: Is this the right diagnostic in the -DUSING case?
45template<typename> int func_tpl(); // expected-error-re {{{{declaration of 'func_tpl' in module M follows declaration in the global module|conflicts with target of using declaration}}}}
46template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module M follows declaration in the global module}}
47template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module M follows declaration in the global module}}
48
49typedef int type;
50namespace ns { using ::func; }
51namespace ns_alias = ns;
52
53#ifdef EXPORT
54}
55#endif
56