[clang] [C] Diagnose use of C++ keywords in C (PR #137234)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri May 2 06:31:44 PDT 2025


================
@@ -250,6 +250,32 @@ static KeywordStatus getKeywordStatus(const LangOptions &LangOpts,
   return CurStatus;
 }
 
+static bool IsKeywordInCpp(unsigned Flags) {
+  while (Flags != 0) {
+    unsigned CurFlag = Flags & ~(Flags - 1);
+    Flags = Flags & ~CurFlag;
+    switch (static_cast<TokenKey>(CurFlag)) {
+    case KEYCXX:
+    case KEYCXX11:
+    case KEYCXX20:
+    case BOOLSUPPORT:
+    case WCHARSUPPORT:
+    case CHAR8SUPPORT:
+      return true;
+    default:
+      break; // Go to the next flag, try again.
+    }
+  }
+  return false;
----------------
AaronBallman wrote:

Code was lifted from https://github.com/llvm/llvm-project/blob/a4ceac7e3e04c32cb3e334eb89b54d8e99a298f8/clang/lib/Basic/IdentifierTable.cpp#L240 but yeah, this seems to be something I can simplify

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


More information about the cfe-commits mailing list