[clang] [C++26] Implement P2843R3 - Preprocessing is never undefined (define/undef keyword part) (PR #218322)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 26 01:43:22 PDT 2026
================
@@ -213,7 +215,16 @@ static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) {
static MacroDiag shouldWarnOnMacroUndef(Preprocessor &PP, IdentifierInfo *II) {
const LangOptions &Lang = PP.getLangOpts();
- // Do not warn on keyword undef. It is generally harmless and widely used.
+ StringRef Text = II->getName();
+ if (II->isKeyword(Lang))
+ return MD_KeywordUndef;
+
+ // [lex.name]/p2: Identifiers with special meaning
+ if ((Lang.CPlusPlus26 && (Text == "post" || Text == "pre")) ||
+ (Lang.CPlusPlus20 && (Text == "module" || Text == "import")) ||
+ (Lang.CPlusPlus11 && (Text == "override" || Text == "final")))
+ return MD_KeywordUndef;
+
----------------
cor3ntin wrote:
I do actually wonder if we shouldn't warn on these unconditionally.
Although we could use a different warning depending on whether the keyword is useful in a given language modes.
In particular
- I don't see any reason why we would not allow contracts in oldfer language modes
- We do accept final / override in C++98 mode today
@hubert-reinterpretcast @AaronBallman
https://github.com/llvm/llvm-project/pull/218322
More information about the cfe-commits
mailing list