This PR is 2nd part of [P1857R3](https://github.com/llvm/llvm-project/pull/107168) implementation, and mainly implement the restriction `A module directive may only appear as the first preprocessing tokens in a file (excluding the global module fragment.)`: [cpp.pre](https://eel.is/c++draft/cpp.pre): ``` module-file: pp-global-module-fragment[opt] pp-module group[opt] pp-private-module-fragment[opt] ``` We also refine tests use `split-file` instead of conditional macro. Signed-off-by: yronglin <yronglin777@gmail.com>
61 lines
2.1 KiB
C++
61 lines
2.1 KiB
C++
// Tests for module-declaration syntax.
|
|
//
|
|
// RUN: rm -rf %t
|
|
// RUN: mkdir %t
|
|
// RUN: split-file %s %t
|
|
//
|
|
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/x.cppm -o %t/x.pcm
|
|
// RUN: %clang_cc1 -std=c++20 -emit-module-interface -fmodule-file=x=%t/x.pcm %t/x.y.cppm -o %t/x.y.pcm
|
|
//
|
|
// Module implementation for unknown and known module. (The former is ill-formed.)
|
|
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify -x c++ %t/z_impl.cppm
|
|
// 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/x_impl.cppm
|
|
//
|
|
// Module interface for unknown and known module. (The latter is ill-formed due to
|
|
// redefinition.)
|
|
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify %t/z_interface.cppm
|
|
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify %t/x_interface.cppm
|
|
//
|
|
// Miscellaneous syntax.
|
|
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify %t/invalid_module_name.cppm
|
|
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify %t/empty_attribute.cppm
|
|
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify %t/fancy_attribute.cppm
|
|
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=x.y=%t/x.y.pcm -verify %t/maybe_unused_attribute.cppm
|
|
|
|
//--- x.cppm
|
|
export module x;
|
|
int a, b;
|
|
|
|
//--- x.y.cppm
|
|
export module x.y;
|
|
int c;
|
|
|
|
//--- z_impl.cppm
|
|
module z; // expected-error {{module 'z' not found}}
|
|
|
|
//--- x_impl.cppm
|
|
// expected-no-diagnostics
|
|
module x;
|
|
|
|
//--- z_interface.cppm
|
|
// expected-no-diagnostics
|
|
export module z;
|
|
|
|
//--- x_interface.cppm
|
|
// expected-no-diagnostics
|
|
export module x;
|
|
|
|
//--- invalid_module_name.cppm
|
|
export module z elderberry; // expected-error {{expected ';'}} \
|
|
// expected-error {{a type specifier is required}}
|
|
|
|
//--- empty_attribute.cppm
|
|
// expected-no-diagnostics
|
|
export module z [[]];
|
|
|
|
//--- fancy_attribute.cppm
|
|
export module z [[fancy]]; // expected-warning {{unknown attribute 'fancy' ignored}}
|
|
|
|
//--- maybe_unused_attribute.cppm
|
|
export module z [[maybe_unused]]; // expected-error-re {{'maybe_unused' attribute cannot be applied to a module{{$}}}}
|