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.cppm
5+ // RUN: %clang_cc1 -std=c++20 -verify %t/ImportError1.cppm
6+ // RUN: %clang_cc1 -std=c++20 -verify %t/ImportError2.cppm
7+ // RUN: %clang_cc1 -std=c++20 -Wno-reserved-module-identifier -emit-module-interface %t/std.cppm -o %t/std.pcm
8+ // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/A.cppm -o %t/A.pcm
9+ // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/A-B.cppm -o %t/A-B.pcm
10+ // RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify -fmodule-file=std=%t/std.pcm -fmodule-file=A=%t/A.pcm -fmodule-file=A:B=%t/A-B.pcm %t/A_impl.cppm
11+ // RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify -fmodule-file=A=%t/A.pcm %t/User.cppm
12+
13+ // --- M.cppm
514module ;
615
7- #if IMPORT_ERROR != 2
816struct import { struct inner {}; };
9- #endif
1017struct module { struct inner {}; };
11-
1218constexpr int n = 123 ;
1319
1420export 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
3321module y = {}; // expected-error {{multiple module declarations}} expected-error 2{{}}
3422// expected-note@#1 {{previous module declaration}}
3523
@@ -51,4 +39,71 @@ template<typename T> module module_var_template;
5139
5240// This is a variable named 'import' that shadows the type 'import' above.
5341struct X {} import ;
54- #endif
42+
43+ // --- ImportError1.cppm
44+ module ;
45+
46+ struct import { struct inner {}; };
47+ struct module { struct inner {}; };
48+
49+ constexpr int n = 123 ;
50+
51+ export module m; // #1
52+
53+ import x = {}; // expected-error {{expected ';' after module name}}
54+ // expected-error@-1 {{module 'x' not found}}
55+
56+ // --- ImportError2.cppm
57+ module ;
58+
59+ struct module { struct inner {}; };
60+
61+ constexpr int n = 123 ;
62+
63+ export module m; // #1
64+
65+ struct X ;
66+ template <int > struct import ;
67+ template <> struct import <n> {
68+ static X y;
69+ };
70+
71+ // This is not valid because the 'import <n>' is a pp-import, even though it
72+ // grammatically can't possibly be an import declaration.
73+ struct X {} import <n>::y; // expected-error {{'n' file not found}}
74+
75+ // --- A.cppm
76+ export module A;
77+ const double delta=0.01 ;
78+ export {
79+ template <class F >
80+ double derivative (F &&f,double x) {
81+ return (f (x+delta)-f (x))/delta;
82+ }
83+ }
84+
85+ // --- std.cppm
86+ export module std;
87+ export using size_t = decltype (sizeof (void *));
88+
89+ export namespace std {
90+ template <typename T, size_t N>
91+ struct array {};
92+ }
93+
94+ // --- A-B.cppm
95+ module A:B;
96+ const int dimensions=3 ;
97+
98+ // --- A_impl.cppm
99+ // expected-no-diagnostics
100+ module A;
101+ import std;
102+ import :B;
103+
104+ using vector = std::array<double , dimensions>; // error: lookup failed until P2788R0(Linkage for modular constants).
105+
106+ // --- User.cppm
107+ // expected-no-diagnostics
108+ import A;
109+ double d=derivative([](double x) {return x*x;},2 ); // error: names delta until P2788R0(Linkage for modular constants).
0 commit comments