[clang] [C++26] Implement P2843R3 - Preprocessing is never undefined (define/undef keyword part) (PR #218322)

Yihan Wang via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 27 00:49:04 PDT 2026


================
@@ -213,7 +215,11 @@ 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;
+  if (Lang.CPlusPlus11 && (Text == "override" || Text == "final"))
+    return MD_KeywordUnDef;
   if (isReservedInAllContexts(II->isReserved(Lang)))
     return MD_ReservedMacro;
   if (isReservedCXXAttributeName(PP, II))
----------------
yronglin wrote:

Hmm, yes, I think we need more precise control to reduce interference with users.

https://github.com/llvm/llvm-project/pull/218322


More information about the cfe-commits mailing list