[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 3 05:18:47 PDT 2024
================
@@ -2686,18 +2693,31 @@ bool Parser::ParseModuleName(
}
Diag(Tok, diag::err_module_expected_ident) << IsImport;
- SkipUntil(tok::semi);
+ SkipUntil(tok::semi, StopBeforeMatch);
return true;
}
- // Record this part of the module path.
- Path.push_back(std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation()));
+ Token Identifier = Tok;
ConsumeToken();
- if (Tok.isNot(tok::period))
- return false;
+ // P3034R1: Module Declarations Shouldn’t be Macros.
+ const auto *MI = PP.getMacroInfo(Identifier.getIdentifierInfo());
+ if (!IsImport && MI) {
+ HasMacroInModuleName = true;
+ if (MI->isFunctionLike())
+ SkipUntil(tok::r_paren, tok::period, tok::colon,
+ StopAtSemi | StopBeforeMatch);
+ Diag(Identifier, diag::err_module_decl_cannot_be_macros)
+ << Identifier.getLocation() << IsPartition << MI->isFunctionLike()
+ << Identifier.getIdentifierInfo();
+ } else if (!HasMacroInModuleName) {
+ // Record this part of the module path.
+ Path.push_back(std::make_pair(Identifier.getIdentifierInfo(),
+ Identifier.getLocation()));
+ }
----------------
cor3ntin wrote:
Having a function-like macro name in a module.
It would not be treated as a macro name because function-like macro are only replaced when a `(` follows, which can never be the case here.
in the tests below, `export module A.FUNC_LIKE` should be a valid module name
(and `export module A.FUNC_LIKE()` should be ill-formed with an `(` cannot appear in a module name,
or you can have a custom diag explaining that macros are not expanded in module names)
https://github.com/llvm/llvm-project/pull/90574
More information about the cfe-commits
mailing list