From e574833c2bc46a39150156eb973d0efb142bc618 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Tue, 28 Mar 2023 08:52:37 -0400 Subject: Downgrade reserved module identifier error into a warning Any project that wants to import std; potentially needs to be able to build a module that does export std;. We silenced the error diagnostic if the module identified itself as a system header, but this isn't quite good enough, what we really need is a way to identify a system module. It would be nice for that feature to be shared among the major implementations, so this downgrades the diagnostic from an error to a warning temporarily to give implementers time to determine what that mechanism will look like. We may convert this warning back into an error in a future release of Clang, but it's not guaranteed we will do so. Fixes https://github.com/llvm/llvm-project/issues/61446 Differential Revision: https://reviews.llvm.org/D146986 --- clang/lib/Sema/SemaModule.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'clang/lib/Sema/SemaModule.cpp') diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 8c120d2..40ebc9c 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -156,11 +156,15 @@ static bool DiagReservedModuleName(Sema &S, const IdentifierInfo *II, if (Reason == Reserved && S.getSourceManager().isInSystemHeader(Loc)) Reason = Valid; - if (Reason != Valid) { - S.Diag(Loc, diag::err_invalid_module_name) << II << (int)Reason; - return true; + switch (Reason) { + case Valid: + return false; + case Invalid: + return S.Diag(Loc, diag::err_invalid_module_name) << II; + case Reserved: + return S.Diag(Loc, diag::warn_reserved_module_name) << II; } - return false; + llvm_unreachable("fell off a fully covered switch"); } Sema::DeclGroupPtrTy @@ -264,8 +268,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, (FirstComponentName == "std" || (FirstComponentName.startswith("std") && llvm::all_of(FirstComponentName.drop_front(3), &llvm::isDigit)))) { - Diag(Path[0].second, diag::err_invalid_module_name) - << Path[0].first << /*reserved*/ 1; + Diag(Path[0].second, diag::warn_reserved_module_name) << Path[0].first; return nullptr; } -- cgit v1.1