diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-04-14 08:06:59 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-04-14 08:06:59 +0000 |
commit | 33eb2fffd975207bf64cb479d6eb9493d5f4110d (patch) | |
tree | e738293b3a1d3db5dd5d63eebbdee7c6bb307849 /test/CXX | |
parent | c923a9876950bf0126dd4ea4d083999e3ff27505 (diff) |
[c++20] Parsing support for module-declarations, import-declarations,
and the global and private module fragment.
For now, the private module fragment introducer is ignored, but use of
the global module fragment introducer should be properly enforced.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358353 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX')
-rw-r--r-- | test/CXX/basic/basic.link/p1.cpp | 37 | ||||
-rw-r--r-- | test/CXX/basic/basic.link/p3.cpp | 53 | ||||
-rw-r--r-- | test/CXX/module/module.unit/p3.cpp | 4 | ||||
-rw-r--r-- | test/CXX/modules-ts/basic/basic.link/module-declaration.cpp | 34 |
4 files changed, 107 insertions, 21 deletions
diff --git a/test/CXX/basic/basic.link/p1.cpp b/test/CXX/basic/basic.link/p1.cpp new file mode 100644 index 0000000000..b94e57017f --- /dev/null +++ b/test/CXX/basic/basic.link/p1.cpp @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -std=c++2a -verify %s +// RUN: %clang_cc1 -std=c++2a -verify -DNO_GLOBAL_FRAG %s +// RUN: %clang_cc1 -std=c++2a -verify -DNO_MODULE_DECL %s +// RUN: %clang_cc1 -std=c++2a -verify -DEXPORT_FRAGS %s + +#ifdef NO_GLOBAL_FRAG +// expected-error@#mod-decl {{module declaration must occur at the start of the translation unit}} +// expected-note@1 {{add 'module;' to the start of the file to introduce a global module fragment}} +#else +#ifdef EXPORT_FRAGS +export // expected-error {{global module fragment cannot be exported}} +#endif +module; // #glob-frag +#endif + +extern int a; // #a1 + +#ifdef NO_MODULE_DECL +// expected-error@#glob-frag {{missing 'module' declaration at end of global module fragment introduced here}} +#else +export module Foo; // #mod-decl + +// expected-error@#a2 {{declaration of 'a' in module Foo follows declaration in the global module}} +// expected-note@#a1 {{previous decl}} +#endif + +int a; // #a2 +extern int b; + +module; // expected-error {{'module;' introducing a global module fragment can appear only at the start of the translation unit}} + +#ifdef EXPORT_FRAGS +export // expected-error {{private module fragment cannot be exported}} +#endif +module :private; + +int b; // ok diff --git a/test/CXX/basic/basic.link/p3.cpp b/test/CXX/basic/basic.link/p3.cpp new file mode 100644 index 0000000000..23f39d11b6 --- /dev/null +++ b/test/CXX/basic/basic.link/p3.cpp @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -std=c++2a -verify %s +// RUN: %clang_cc1 -std=c++2a -verify %s -DIMPORT_ERROR=1 +// RUN: %clang_cc1 -std=c++2a -verify %s -DIMPORT_ERROR=2 + +module; + +#if IMPORT_ERROR != 2 +struct import { struct inner {}; }; +#endif +struct module { struct inner {}; }; + +constexpr int n = 123; + +export module m; // #1 + +// Import errors are fatal, so we test them in isolation. +#if IMPORT_ERROR == 1 +import x = {}; // expected-error {{module 'x' not found}} + +#elif IMPORT_ERROR == 2 +struct X; +template<int> struct import; +template<> struct import<n> { + static X y; +}; + +// This is not valid because the 'import <n>' is a pp-import, even though it +// grammatically can't possibly be an import declaration. +struct X {} import<n>::y; // expected-error {{'n' file not found}} + +#else +module y = {}; // expected-error {{multiple module declarations}} expected-error 2{{}} +// expected-note@#1 {{previous module declaration}} + +::import x = {}; +::module y = {}; + +import::inner xi = {}; +module::inner yi = {}; + +namespace N { + module a; + import b; +} + +extern "C++" module cxxm; +extern "C++" import cxxi; + +template<typename T> module module_var_template; + +// This is a variable named 'import' that shadows the type 'import' above. +struct X {} import; +#endif diff --git a/test/CXX/module/module.unit/p3.cpp b/test/CXX/module/module.unit/p3.cpp new file mode 100644 index 0000000000..2e08f4a9a8 --- /dev/null +++ b/test/CXX/module/module.unit/p3.cpp @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -std=c++2a -verify %s + +export module foo:bar; // expected-error {{sorry, module partitions are not yet supported}} +import :baz; // expected-error {{sorry, module partitions are not yet supported}} diff --git a/test/CXX/modules-ts/basic/basic.link/module-declaration.cpp b/test/CXX/modules-ts/basic/basic.link/module-declaration.cpp index feb0afdda0..7615536b81 100644 --- a/test/CXX/modules-ts/basic/basic.link/module-declaration.cpp +++ b/test/CXX/modules-ts/basic/basic.link/module-declaration.cpp @@ -10,47 +10,39 @@ // // Module implementation for unknown and known module. (The former is ill-formed.) // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=1 -DEXPORT= -DPARTITION= -DMODULE_NAME=z +// RUN: -DTEST=1 -DEXPORT= -DMODULE_NAME=z // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=2 -DEXPORT= -DPARTITION= -DMODULE_NAME=x +// RUN: -DTEST=2 -DEXPORT= -DMODULE_NAME=x // // Module interface for unknown and known module. (The latter is ill-formed due to // redefinition.) // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=3 -DEXPORT=export -DPARTITION= -DMODULE_NAME=z +// RUN: -DTEST=3 -DEXPORT=export -DMODULE_NAME=z // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=4 -DEXPORT=export -DPARTITION= -DMODULE_NAME=x -// -// Defining a module partition. -// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=5 -DEXPORT=export -DPARTITION=partition -DMODULE_NAME=z -// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=6 -DEXPORT= -DPARTITION=partition -DMODULE_NAME=z +// RUN: -DTEST=4 -DEXPORT=export -DMODULE_NAME=x // // Miscellaneous syntax. // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=7 -DEXPORT= -DPARTITION=elderberry -DMODULE_NAME=z +// RUN: -DTEST=7 -DEXPORT=export -DMODULE_NAME='z elderberry' // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=8 -DEXPORT=export -DPARTITION= -DMODULE_NAME='z [[]]' +// RUN: -DTEST=8 -DEXPORT=export -DMODULE_NAME='z [[]]' // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=9 -DEXPORT=export -DPARTITION= -DMODULE_NAME='z [[fancy]]' +// RUN: -DTEST=9 -DEXPORT=export -DMODULE_NAME='z [[fancy]]' // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \ -// RUN: -DTEST=10 -DEXPORT=export -DPARTITION= -DMODULE_NAME='z [[maybe_unused]]' +// RUN: -DTEST=10 -DEXPORT=export -DMODULE_NAME='z [[maybe_unused]]' -EXPORT module PARTITION MODULE_NAME; +EXPORT module MODULE_NAME; #if TEST == 4 // expected-error@-2 {{redefinition of module 'x'}} // expected-note-re@module-declaration.cpp:* {{loaded from '{{.*[/\\]}}x.pcm'}} -#elif TEST == 6 -// expected-error@-5 {{module partition must be declared 'export'}} #elif TEST == 7 -// expected-error@-7 {{expected ';'}} expected-error@-7 {{requires a type specifier}} expected-error@-7 {{definition of module 'elderberry' is not available}} +// expected-error@-5 {{expected ';'}} expected-error@-5 {{requires a type specifier}} #elif TEST == 9 -// expected-warning@-9 {{unknown attribute 'fancy' ignored}} +// expected-warning@-7 {{unknown attribute 'fancy' ignored}} #elif TEST == 10 -// expected-error-re@-11 {{'maybe_unused' attribute cannot be applied to a module{{$}}}} +// expected-error-re@-9 {{'maybe_unused' attribute cannot be applied to a module{{$}}}} #elif TEST == 1 -// expected-error@-13 {{definition of module 'z' is not available}} +// expected-error@-11 {{definition of module 'z' is not available}} #else // expected-no-diagnostics #endif |