Clang Project

clang_source_code/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.import/p1.cpp
1// RUN: rm -rf %t
2// RUN: mkdir -p %t
3// RUN: echo 'export module x; export int a, b;' > %t/x.cppm
4// RUN: echo 'export module x.y; export int c;' > %t/x.y.cppm
5// RUN: echo 'export module a.b; export int d;' > %t/a.b.cppm
6//
7// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %t/x.cppm -o %t/x.pcm
8// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface -fmodule-file=%t/x.pcm %t/x.y.cppm -o %t/x.y.pcm
9// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %t/a.b.cppm -o %t/a.b.pcm
10//
11// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -fmodule-file=%t/a.b.pcm -verify %s \
12// RUN:            -DMODULE_NAME=z -DINTERFACE
13// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -fmodule-file=%t/a.b.pcm -verify %s \
14// RUN:            -DMODULE_NAME=a.b
15// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -fmodule-file=%t/a.b.pcm -verify %s \
16// RUN:            -DMODULE_X -DMODULE_NAME=x
17
18#ifdef INTERFACE
19export
20#endif
21module MODULE_NAME;
22
23int use_1 = a;
24#if !MODULE_X
25// expected-error@-2 {{declaration of 'a' must be imported from module 'x' before it is required}}
26// expected-note@x.cppm:1 {{here}}
27#endif
28
29import x;
30
31int use_2 = b; // ok
32
33// There is no relation between module x and module x.y.
34int use_3 = c; // expected-error {{declaration of 'c' must be imported from module 'x.y'}}
35               // expected-note@x.y.cppm:1 {{here}}
36
37import x [[]];
38import x [[foo]]; // expected-warning {{unknown attribute 'foo' ignored}}
39import x [[noreturn]]; // expected-error {{'noreturn' attribute cannot be applied to a module import}}
40import x [[blarg::noreturn]]; // expected-warning {{unknown attribute 'noreturn' ignored}}
41
42import x.y;
43import a.b; // Does not imply existence of module a.
44import x.; // expected-error {{expected a module name after 'import'}}
45import .x; // expected-error {{expected a module name after 'import'}}
46
47int use_4 = c; // ok
48
49import blarg; // expected-error {{module 'blarg' not found}}
50