diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2025-05-02 07:20:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-02 07:20:02 -0400 |
commit | 85c810060e1a2a90dc4ec184b4c4275db17ef28f (patch) | |
tree | 28b3fe6f699647511cef8ef915793ef367f6ee23 /clang/lib/Lex/Preprocessor.cpp | |
parent | 3d4f979e271d2a1fe0906f4d1b16db108838f98f (diff) | |
download | llvm-85c810060e1a2a90dc4ec184b4c4275db17ef28f.zip llvm-85c810060e1a2a90dc4ec184b4c4275db17ef28f.tar.gz llvm-85c810060e1a2a90dc4ec184b4c4275db17ef28f.tar.bz2 |
[C] Diagnose use of C++ keywords in C (#137234)
This adds a new diagnostic group, -Wc++-keyword, which is off by default
and grouped under -Wc++-compat. The diagnostic catches use of C++
keywords in C code.
This change additionally fixes an issue with -Wreserved-identifier not
diagnosing use of reserved identifiers in function parameter lists in a
function declaration which is not a definition.
Fixes https://github.com/llvm/llvm-project/issues/21898
Diffstat (limited to 'clang/lib/Lex/Preprocessor.cpp')
-rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 4c050bf..9ea7b95 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -834,6 +834,11 @@ bool Preprocessor::HandleIdentifier(Token &Identifier) { II.setIsFutureCompatKeyword(false); } + // If this identifier would be a keyword in C++, diagnose as a compatibility + // issue. + if (II.IsKeywordInCPlusPlus() && !DisableMacroExpansion) + Diag(Identifier, diag::warn_pp_identifier_is_cpp_keyword) << &II; + // If this is an extension token, diagnose its use. // We avoid diagnosing tokens that originate from macro definitions. // FIXME: This warning is disabled in cases where it shouldn't be, |