[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
Nikita Popov via cfe-commits
cfe-commits at lists.llvm.org
Fri May 2 06:27:02 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;
----------------
nikic wrote:
I'm a bit confused by this function. Why does this go through all bits in a loop instead of directly checking them? I'd have expected this whole function to be something like `return Flags & (KEYALLCXX|BOOLSUPPORT|WCHARSUPPORT|CHAR8SUPPORT);`
https://github.com/llvm/llvm-project/pull/137234
More information about the cfe-commits
mailing list