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
59module ;
610
7- #if IMPORT_ERROR != 2
811struct import { struct inner {}; };
9- #endif
1012struct module { struct inner {}; };
11-
1213constexpr int n = 123 ;
1314
1415export 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
3316module 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.
5336struct 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