xref: /llvm-project/clang/test/CXX/basic/basic.link/p3.cpp (revision 676b48d1ccd8223bb0bd889cce13e6faecd20c6d)
1d652bdd0SRichard Smith // RUN: %clang_cc1 -std=c++2a -verify %s
2d652bdd0SRichard Smith // RUN: %clang_cc1 -std=c++2a -verify %s -DIMPORT_ERROR=1
3d652bdd0SRichard Smith // RUN: %clang_cc1 -std=c++2a -verify %s -DIMPORT_ERROR=2
4d652bdd0SRichard Smith 
5d652bdd0SRichard Smith module;
6d652bdd0SRichard Smith 
7d652bdd0SRichard Smith #if IMPORT_ERROR != 2
8d652bdd0SRichard Smith struct import { struct inner {}; };
9d652bdd0SRichard Smith #endif
10d652bdd0SRichard Smith struct module { struct inner {}; };
11d652bdd0SRichard Smith 
12d652bdd0SRichard Smith constexpr int n = 123;
13d652bdd0SRichard Smith 
14d652bdd0SRichard Smith export module m; // #1
15d652bdd0SRichard Smith 
16d652bdd0SRichard Smith // Import errors are fatal, so we test them in isolation.
17d652bdd0SRichard Smith #if IMPORT_ERROR == 1
18*676b48d1SChuanqi Xu import x = {}; // expected-error {{expected ';' after module name}}
19*676b48d1SChuanqi Xu                // expected-error@-1 {{module 'x' not found}}
20d652bdd0SRichard Smith 
21d652bdd0SRichard Smith #elif IMPORT_ERROR == 2
22d652bdd0SRichard Smith struct X;
23d652bdd0SRichard Smith template<int> struct import;
24d652bdd0SRichard Smith template<> struct import<n> {
25d652bdd0SRichard Smith   static X y;
26d652bdd0SRichard Smith };
27d652bdd0SRichard Smith 
28d652bdd0SRichard Smith // This is not valid because the 'import <n>' is a pp-import, even though it
29d652bdd0SRichard Smith // grammatically can't possibly be an import declaration.
30d652bdd0SRichard Smith struct X {} import<n>::y; // expected-error {{'n' file not found}}
31d652bdd0SRichard Smith 
32d652bdd0SRichard Smith #else
33d652bdd0SRichard Smith module y = {}; // expected-error {{multiple module declarations}} expected-error 2{{}}
34d652bdd0SRichard Smith // expected-note@#1 {{previous module declaration}}
35d652bdd0SRichard Smith 
36d652bdd0SRichard Smith ::import x = {};
37d652bdd0SRichard Smith ::module y = {};
38d652bdd0SRichard Smith 
39d652bdd0SRichard Smith import::inner xi = {};
40d652bdd0SRichard Smith module::inner yi = {};
41d652bdd0SRichard Smith 
42d652bdd0SRichard Smith namespace N {
43d652bdd0SRichard Smith   module a;
44d652bdd0SRichard Smith   import b;
45d652bdd0SRichard Smith }
46d652bdd0SRichard Smith 
47d652bdd0SRichard Smith extern "C++" module cxxm;
48d652bdd0SRichard Smith extern "C++" import cxxi;
49d652bdd0SRichard Smith 
50d652bdd0SRichard Smith template<typename T> module module_var_template;
51d652bdd0SRichard Smith 
52d652bdd0SRichard Smith // This is a variable named 'import' that shadows the type 'import' above.
53d652bdd0SRichard Smith struct X {} import;
54d652bdd0SRichard Smith #endif
55