[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 3 06:52:29 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()));
+ }
----------------
yronglin wrote:
Thanks! I've fixed this issue. Hmm, I tried to add a note diagnostic in local, but seems it's a bit noisy and redundant.
```
➜ test ../rel/bin/clang++ -c -std=c++20 ./lib.cppm
./lib.cppm:6:15: error: the name of a module declaration cannot contains an object-like macro 'A'
6 | export module A.FUNC_LIKE():CC;
| ^
./lib.cppm:6:15: note: object-like macro in the name of a module declaration will not expand
6 | export module A.FUNC_LIKE():CC;
| ^
./lib.cppm:6:17: error: the name of a module declaration cannot contains a function-like macro 'FUNC_LIKE'
6 | export module A.FUNC_LIKE():CC;
| ^~~~~~~~~~~
./lib.cppm:6:17: note: function-like macro in the name of a module partition declaration will not expand
6 | export module A.FUNC_LIKE():CC;
| ^~~~~~~~~~~
./lib.cppm:6:29: error: the name of a module partition declaration cannot contains an object-like macro 'CC'
6 | export module A.FUNC_LIKE():CC;
| ^~
./lib.cppm:6:29: note: object-like macro in the name of a module declaration will not expand
6 | export module A.FUNC_LIKE():CC;
| ^~
3 errors generated.
```
https://github.com/llvm/llvm-project/pull/90574
More information about the cfe-commits
mailing list