blob: 0600eddecb834ae94e76f65debf922d8f43c46d7 [file] [log] [blame]
Richard Smith49cc1cc2016-08-18 21:59:42 +00001// RUN: rm -rf %t
2// RUN: mkdir -p %t
Richard Smithbbcc9f02016-08-26 00:14:38 +00003// RUN: echo 'module x; int a, b;' > %t/x.cppm
4// RUN: echo 'module x.y; int c;' > %t/x.y.cppm
5//
6// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %t/x.cppm -o %t/x.pcm
7// 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
8//
9// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
Richard Smith964cc532016-08-19 01:43:06 +000010// RUN: -DTEST=1 -DMODULE_KIND=implementation -DMODULE_NAME=z
Richard Smithbbcc9f02016-08-26 00:14:38 +000011// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
Richard Smith964cc532016-08-19 01:43:06 +000012// RUN: -DTEST=2 -DMODULE_KIND=implementation -DMODULE_NAME=x
Richard Smithbbcc9f02016-08-26 00:14:38 +000013// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
Richard Smith964cc532016-08-19 01:43:06 +000014// RUN: -DTEST=3 -DMODULE_KIND= -DMODULE_NAME=z
Richard Smithbbcc9f02016-08-26 00:14:38 +000015// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
Richard Smith964cc532016-08-19 01:43:06 +000016// RUN: -DTEST=4 -DMODULE_KIND=partition -DMODULE_NAME=z
Richard Smithbbcc9f02016-08-26 00:14:38 +000017// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
Richard Smith964cc532016-08-19 01:43:06 +000018// RUN: -DTEST=5 -DMODULE_KIND=elderberry -DMODULE_NAME=z
Richard Smithbbcc9f02016-08-26 00:14:38 +000019// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
Richard Smith964cc532016-08-19 01:43:06 +000020// RUN: -DTEST=1 -DMODULE_KIND=implementation -DMODULE_NAME='z [[]]'
Richard Smithbbcc9f02016-08-26 00:14:38 +000021// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
Richard Smith964cc532016-08-19 01:43:06 +000022// RUN: -DTEST=6 -DMODULE_KIND=implementation -DMODULE_NAME='z [[fancy]]'
Richard Smithbbcc9f02016-08-26 00:14:38 +000023// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
Richard Smith964cc532016-08-19 01:43:06 +000024// RUN: -DTEST=7 -DMODULE_KIND=implementation -DMODULE_NAME='z [[maybe_unused]]'
Richard Smith49cc1cc2016-08-18 21:59:42 +000025
Richard Smith964cc532016-08-19 01:43:06 +000026module MODULE_KIND MODULE_NAME;
27#if TEST == 3
28// expected-error@-2 {{'module' declaration found while not building module interface}}
29#elif TEST == 4
30// expected-error@-4 {{'module partition' declaration found while not building module interface}}
31#elif TEST == 5
32// expected-error@-6 {{unexpected module kind 'elderberry'}}
33#elif TEST == 6
34// expected-warning@-8 {{unknown attribute 'fancy' ignored}}
35#elif TEST == 7
36// expected-error-re@-10 {{'maybe_unused' attribute cannot be applied to a module{{$}}}}
37#endif
38
39int use_1 = a;
40#if TEST != 2
Richard Smithbbcc9f02016-08-26 00:14:38 +000041// expected-error@-2 {{declaration of 'a' must be imported from module 'x' before it is required}}
42// expected-note@x.cppm:1 {{here}}
Richard Smith964cc532016-08-19 01:43:06 +000043#endif
Richard Smith49cc1cc2016-08-18 21:59:42 +000044
45import x;
46
47int use_2 = b; // ok
48
49import x [[]];
50import x [[foo]]; // expected-warning {{unknown attribute 'foo' ignored}}
51import x [[noreturn]]; // expected-error {{'noreturn' attribute cannot be applied to a module import}}
52import x [[blarg::noreturn]]; // expected-warning {{unknown attribute 'noreturn' ignored}}
53
54import x.y;
55import x.; // expected-error {{expected a module name after module import}}
56import .x; // expected-error {{expected a module name after module import}}
57
58import blarg; // expected-error {{module 'blarg' not found}}