xref: /llvm-project/clang/test/CXX/module/basic/basic.link/module-declaration.cpp (revision e77a01d79a48e15c94c89e4aa4bd27424a96b49b)
1 // Tests for module-declaration syntax.
2 //
3 // RUN: rm -rf %t
4 // RUN: mkdir %t
5 // RUN: split-file %s %t
6 //
7 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/x.cppm -o %t/x.pcm
8 // RUN: %clang_cc1 -std=c++20 -emit-module-interface -fmodule-file=x=%t/x.pcm %t/x.y.cppm -o %t/x.y.pcm
9 //
10 // Module implementation for unknown and known module. (The former is ill-formed.)
11 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify -x c++ %t/M1.cpp
12 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x=%t/x.pcm -fmodule-file=x.y=%t/x.y.pcm -verify -x c++ %t/M2.cpp
13 //
14 // Module interface for unknown and known module. (The latter is ill-formed due to
15 // redefinition.)
16 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify %t/M3.cpp
17 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify %t/M4.cpp
18 //
19 // Miscellaneous syntax.
20 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify %t/M5.cpp
21 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify %t/M6.cpp
22 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify %t/M7.cpp
23 // RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify %t/M8.cpp
24 
25 //--- x.cppm
26 export module x;
27 int a, b;
28 
29 //--- x.y.cppm
30 export module x.y;
31 int c;
32 
33 //--- M1.cpp
34 module z; // expected-error {{module 'z' not found}}
35 
36 //--- M2.cpp
37 module x; // expected-no-diagnostics
38 
39 //--- M3.cpp
40 export module z; // expected-no-diagnostics
41 
42 //--- M4.cpp
43 export module x; // expected-no-diagnostics
44 
45 //--- M5.cpp
46 export module z elderberry; // expected-error {{expected ';'}} expected-error {{a type specifier is required}}
47 
48 //--- M6.cpp
49 export module z [[]]; // expected-no-diagnostics
50 
51 //--- M7.cpp
52 export module z [[fancy]]; // expected-warning {{unknown attribute 'fancy' ignored}}
53 
54 //--- M8.cpp
55 export module z [[maybe_unused]]; // expected-error-re {{'maybe_unused' attribute cannot be applied to a module{{$}}}}
56