[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 30 08:08:57 PDT 2024
================
@@ -2690,6 +2690,13 @@ bool Parser::ParseModuleName(
return true;
}
+ // P3034R1: Module Declarations Shouldn’t be Macros
+ if (!IsImport && Tok.getLocation().isMacroID()) {
+ Diag(Tok, diag::err_module_decl_cannot_be_macros);
+ SkipUntil(tok::semi);
+ return true;
----------------
yronglin wrote:
I've a case like the following:
```
// version.h
#ifndef VERSION_H
#define VERSION_H
#define VERSION libv5
#define A a
#define B b
#define AB A.B
#endif
// lib.cppm
module;
#include "version.h"
export module AB;
export module x:A;
export module VERSION;
export module A.B;
```
We get the following diagnostic message:
```
-> test ../rel/bin/clang++ -c -std=c++20 ./lib.cppm
./lib.cppm:3:15: error: module declaration cannot be a macro
3 | export module AB;
| ^
./version.h:7:12: note: expanded from macro 'AB'
7 | #define AB A.B
| ^
./version.h:5:11: note: expanded from macro 'A'
5 | #define A a
| ^
./lib.cppm:3:15: error: module declaration cannot be a macro
./version.h:7:14: note: expanded from macro 'AB'
7 | #define AB A.B
| ^
./version.h:6:11: note: expanded from macro 'B'
6 | #define B b
| ^
./lib.cppm:4:17: error: module declaration cannot be a macro
4 | export module x:A;
| ^
./version.h:5:11: note: expanded from macro 'A'
5 | #define A a
| ^
./lib.cppm:5:15: error: module declaration cannot be a macro
5 | export module VERSION;
| ^
./version.h:4:17: note: expanded from macro 'VERSION'
4 | #define VERSION libv5
| ^
./lib.cppm:6:15: error: module declaration cannot be a macro
6 | export module A.B;
| ^
./version.h:5:11: note: expanded from macro 'A'
5 | #define A a
| ^
./lib.cppm:6:17: error: module declaration cannot be a macro
6 | export module A.B;
| ^
./version.h:6:11: note: expanded from macro 'B'
6 | #define B b
| ^
./lib.cppm:1:1: error: missing 'module' declaration at end of global module fragment introduced here
1 | module;
| ^
7 errors generated.
```
I feel that `export module AB;`’s error report is not good enough. (Please ignore the error message wording, I am addressing review comments🤣)
https://github.com/llvm/llvm-project/pull/90574
More information about the cfe-commits
mailing list