llvm-project/clang/test/Modules/reserved-names-1.cpp
Aaron Ballman b8ceb9f4e4 [C++20] Diagnose invalid and reserved module names
[module.unit]p1 specifies that module and import are invalid components
of a module name, that module names cannot contain reserved
identifiers, and that std followed by zero or more digits is reserved.

The first issue (module and import pseudo-keywords) requires a
diagnostic, the second issue (use of reserved identifiers) does not
require a diagnostic. We diagnose both the same -- the code is ill-
formed unless the module declaration is in a system "header". This
allows STL implementations to use the reserved module names while
preventing users from stealing them out from under us.

Differential Revision: https://reviews.llvm.org/D136953
2022-11-03 08:29:59 -04:00

46 lines
3.4 KiB
C++

// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
// expected-note@1 15{{add 'module;' to the start of the file to introduce a global module fragment}}
module std; // expected-error {{'std' is a reserved name for a module}}
module _Test; // expected-error {{'_Test' is a reserved name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
module module; // expected-error {{'module' is an invalid name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
module std0; // expected-error {{'std0' is a reserved name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
export module module; // expected-error {{'module' is an invalid name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
export module import; // expected-error {{'import' is an invalid name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
export module _Test; // expected-error {{'_Test' is a reserved name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
export module __test; // expected-error {{'__test' is a reserved name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
export module te__st; // expected-error {{'te__st' is a reserved name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
export module std; // expected-error {{'std' is a reserved name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
export module std.foo;// expected-error {{'std' is a reserved name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
export module std0; // expected-error {{'std0' is a reserved name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
export module std1000000; // expected-error {{'std1000000' is a reserved name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
export module should_fail._Test; // expected-error {{'_Test' is a reserved name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
// Show that being in a system header doesn't save you from diagnostics about
// use of an invalid module-name identifier.
# 34 "reserved-names-1.cpp" 1 3
export module module; // expected-error {{'module' is an invalid name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
export module _Test.import; // expected-error {{'import' is an invalid name for a module}} \
expected-error {{module declaration must occur at the start of the translation unit}}
# 39 "reserved-names-1.cpp" 2 3
// We can still use a reserved name on imoport.
import std; // expected-error {{module 'std' not found}}