Skip to content

Commit d679b9a

Browse files
authored
[NFC][C++][Modules] Refine test/CXX/basic.link/p3.cpp with split-file (#147945)
Refine basic.link.p3 tests with split-file. --------- Signed-off-by: Wang, Yihan <yronglin777@gmail.com>
1 parent edd615e commit d679b9a

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed
Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
1-
// RUN: %clang_cc1 -std=c++2a -verify %s
2-
// RUN: %clang_cc1 -std=c++2a -verify %s -DIMPORT_ERROR=1
3-
// RUN: %clang_cc1 -std=c++2a -verify %s -DIMPORT_ERROR=2
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
43

4+
// RUN: %clang_cc1 -std=c++20 -verify %t/M.cpp
5+
// RUN: %clang_cc1 -std=c++20 -verify %t/ImportError1.cpp
6+
// RUN: %clang_cc1 -std=c++20 -verify %t/ImportError2.cpp
7+
8+
//--- M.cpp
59
module;
610

7-
#if IMPORT_ERROR != 2
811
struct import { struct inner {}; };
9-
#endif
1012
struct module { struct inner {}; };
11-
1213
constexpr int n = 123;
1314

1415
export module m; // #1
15-
16-
// Import errors are fatal, so we test them in isolation.
17-
#if IMPORT_ERROR == 1
18-
import x = {}; // expected-error {{expected ';' after module name}}
19-
// expected-error@-1 {{module 'x' not found}}
20-
21-
#elif IMPORT_ERROR == 2
22-
struct X;
23-
template<int> struct import;
24-
template<> struct import<n> {
25-
static X y;
26-
};
27-
28-
// This is not valid because the 'import <n>' is a pp-import, even though it
29-
// grammatically can't possibly be an import declaration.
30-
struct X {} import<n>::y; // expected-error {{'n' file not found}}
31-
32-
#else
3316
module y = {}; // expected-error {{multiple module declarations}} expected-error 2{{}}
3417
// expected-note@#1 {{previous module declaration}}
3518

@@ -51,4 +34,36 @@ template<typename T> module module_var_template;
5134

5235
// This is a variable named 'import' that shadows the type 'import' above.
5336
struct X {} import;
54-
#endif
37+
38+
//--- ImportError1.cpp
39+
module;
40+
41+
struct import { struct inner {}; };
42+
struct module { struct inner {}; };
43+
44+
constexpr int n = 123;
45+
46+
export module m; // #1
47+
48+
import x = {}; // expected-error {{expected ';' after module name}}
49+
// expected-error@-1 {{module 'x' not found}}
50+
51+
//--- ImportError2.cpp
52+
module;
53+
54+
struct module { struct inner {}; };
55+
56+
constexpr int n = 123;
57+
58+
export module m; // #1
59+
60+
struct X;
61+
template<int> struct import;
62+
template<> struct import<n> {
63+
static X y;
64+
};
65+
66+
// This is not valid because the 'import <n>' is a pp-import, even though it
67+
// grammatically can't possibly be an import declaration.
68+
struct X {} import<n>::y; // expected-error {{'n' file not found}}
69+

0 commit comments

Comments
 (0)