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

2025-05-02 Thread Aaron Ballman via cfe-commits
@@ -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

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

2025-05-02 Thread Aaron Ballman via cfe-commits
@@ -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

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

2025-05-02 Thread Nikita Popov via cfe-commits
@@ -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

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

2025-05-02 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman closed https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-05-01 Thread John McCall via cfe-commits
rjmccall wrote: > For what it's worth, the existing "keyword from language you're not using" > warnings [already fire for analogous Objective-C++ > cases](https://godbolt.org/z/3K6835PPK)... which in those cases is correct, > since Clang does _not_ accept C++11-onwards keywords as selector nam

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

2025-05-01 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/20] [C] Diagnose use of C++ keywords in C This adds a ne

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

2025-05-01 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: I've removed support for Objective-C for now; we can come back to it again in the future. https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailm

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

2025-05-01 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman edited https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-04-30 Thread Richard Smith via cfe-commits
zygoloid wrote: For what it's worth, the existing "keyword from language you're not using" warnings [already fire for analogous Objective-C++ cases](https://godbolt.org/z/3K6835PPK)... which in those cases is correct, since Clang does *not* accept C++11-onwards keywords as selector names in th

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

2025-04-30 Thread John McCall via cfe-commits
rjmccall wrote: Yeah, triggering this at the preprocessor level is not going to let you do in properly in Objective-C, where keywords are effectively context-sensitive. If that's the only reasonable way to implement it, you should just turn it off in Objective-C completely. https://github.com

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

2025-04-30 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: > > > Similarly, ObjC selector components exist outside of the normal keyword > > > rules, and the warning should never kick in on them. > > > > > > I don't know about selectors all that much; can you give me a test case > > that you think I should handle? > > In general:

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

2025-04-30 Thread John McCall via cfe-commits
rjmccall wrote: > > Similarly, ObjC selector components exist outside of the normal keyword > > rules, and the warning should never kick in on them. > > I don't know about selectors all that much; can you give me a test case that > you think I should handle? In general: look at `ParseObjCSele

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

2025-04-30 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/19] [C] Diagnose use of C++ keywords in C This adds a ne

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

2025-04-30 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: > The ObjC `@` is essentially an escape into a completely different grammar, > and it doesn't matter whether the following identifier is a keyword or not in > the base language. This warning should never kick in on that identifier. Okay, I've done that. > Similarly, ObjC s

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

2025-04-30 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/19] [C] Diagnose use of C++ keywords in C This adds a ne

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

2025-04-29 Thread John McCall via cfe-commits
rjmccall wrote: The ObjC `@` is essentially an escape into a completely different grammar, and it doesn't matter whether the following identifier is a keyword or not in the base language. This warning should never kick in on that identifier. Similarly, ObjC selector components exist outside of

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

2025-04-29 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: Adding @rjmccall because this touches on Objective-C `@` keyword handling. (Note, maybe we want `-Wc++-compat` to be disabled in Objective-C entirely and we should have `-Wobjc++-compat` instead? `[foo bar];` is not valid C++, but I doubt anyone wants that diagnosed in Obje

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

2025-04-29 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/17] [C] Diagnose use of C++ keywords in C This adds a ne

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

2025-04-29 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/16] [C] Diagnose use of C++ keywords in C This adds a ne

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

2025-04-29 Thread Aaron Ballman via cfe-commits
@@ -6118,6 +6120,10 @@ void Sema::warnOnReservedIdentifier(const NamedDecl *D) { Diag(D->getLocation(), diag::warn_reserved_extern_symbol) << D << static_cast(Status); } + // Diagnose use of C++ keywords in C as being incompatible with C++. + if (const Identifie

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

2025-04-29 Thread Richard Smith via cfe-commits
@@ -6118,6 +6120,10 @@ void Sema::warnOnReservedIdentifier(const NamedDecl *D) { Diag(D->getLocation(), diag::warn_reserved_extern_symbol) << D << static_cast(Status); } + // Diagnose use of C++ keywords in C as being incompatible with C++. + if (const Identifie

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

2025-04-29 Thread Richard Smith via cfe-commits
@@ -258,8 +283,13 @@ static void AddKeyword(StringRef Keyword, const LangOptions &LangOpts, IdentifierTable &Table) { KeywordStatus AddResult = getKeywordStatus(LangOpts, Flags); - // Don't add this keyword if disabled in this language. - if (AddResu

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

2025-04-29 Thread Erich Keane via cfe-commits
https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-04-29 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/15] [C] Diagnose use of C++ keywords in C This adds a ne

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

2025-04-29 Thread Aaron Ballman via cfe-commits
@@ -6107,6 +6109,44 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +constexpr unsigned countCPlusPlusKeywords() { + unsigned Ret = 0; +#define MODULES_KEYWORD(NAME) +#define KEYWORD(NAME, FLAGS) ++Ret; +

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

2025-04-29 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/15] [C] Diagnose use of C++ keywords in C This adds a ne

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

2025-04-28 Thread Aaron Ballman via cfe-commits
@@ -6107,6 +6109,43 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +constexpr unsigned countCPlusPlusKeywords() { + unsigned Ret = 0; +#define MODULES_KEYWORD(NAME) +#define KEYWORD(NAME, FLAGS) ++Ret; +

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

2025-04-28 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/14] [C] Diagnose use of C++ keywords in C This adds a ne

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

2025-04-28 Thread Eli Friedman via cfe-commits
@@ -6107,6 +6109,43 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +constexpr unsigned countCPlusPlusKeywords() { + unsigned Ret = 0; +#define MODULES_KEYWORD(NAME) +#define KEYWORD(NAME, FLAGS) ++Ret; +

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

2025-04-28 Thread Aaron Ballman via cfe-commits
@@ -6107,6 +6109,43 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +constexpr unsigned countCPlusPlusKeywords() { + unsigned Ret = 0; +#define MODULES_KEYWORD(NAME) +#define KEYWORD(NAME, FLAGS) ++Ret; +

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

2025-04-28 Thread Aaron Ballman via cfe-commits
@@ -6107,6 +6109,43 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +constexpr unsigned countCPlusPlusKeywords() { + unsigned Ret = 0; +#define MODULES_KEYWORD(NAME) +#define KEYWORD(NAME, FLAGS) ++Ret; +

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

2025-04-28 Thread Aaron Ballman via cfe-commits
@@ -6107,6 +6109,43 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +constexpr unsigned countCPlusPlusKeywords() { + unsigned Ret = 0; +#define MODULES_KEYWORD(NAME) +#define KEYWORD(NAME, FLAGS) ++Ret; +

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

2025-04-28 Thread Eli Friedman via cfe-commits
@@ -6107,6 +6109,43 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +constexpr unsigned countCPlusPlusKeywords() { + unsigned Ret = 0; +#define MODULES_KEYWORD(NAME) +#define KEYWORD(NAME, FLAGS) ++Ret; +

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

2025-04-28 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/13] [C] Diagnose use of C++ keywords in C This adds a ne

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

2025-04-28 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: After talking with Erich offline, I've updated the implementation to use a binary_search. The pointers are being cast to `uintptr_t` so that the `llvm::sort()` isn't operating on unrelated pointers. https://github.com/llvm/llvm-project/pull/137234 __

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

2025-04-28 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/12] [C] Diagnose use of C++ keywords in C This adds a ne

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

2025-04-28 Thread Erich Keane via cfe-commits
@@ -6107,6 +6109,29 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) { + if (!II) +return false; + + // Build a static map of

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

2025-04-28 Thread Erich Keane via cfe-commits
https://github.com/erichkeane approved this pull request. You can remove the `Params.empty` if you'd like, but this LGTM anyway. https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm

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

2025-04-28 Thread Aaron Ballman via cfe-commits
@@ -6107,6 +6109,29 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) { + if (!II) +return false; + + // Build a static map of

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

2025-04-28 Thread Erich Keane via cfe-commits
@@ -6107,6 +6109,29 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) { + if (!II) +return false; + + // Build a static map of

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

2025-04-28 Thread Aaron Ballman via cfe-commits
@@ -6107,6 +6109,29 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) { + if (!II) +return false; + + // Build a static map of

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

2025-04-28 Thread Aaron Ballman via cfe-commits
@@ -10416,6 +10447,15 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, // Finally, we know we have the right number of parameters, install them. NewFD->setParams(Params); + // If this declarator is a declaration and not a definition, its paramet

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

2025-04-28 Thread Erich Keane via cfe-commits
@@ -6107,6 +6109,29 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) { + if (!II) +return false; + + // Build a static map of

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

2025-04-28 Thread Erich Keane via cfe-commits
@@ -10416,6 +10447,15 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, // Finally, we know we have the right number of parameters, install them. NewFD->setParams(Params); + // If this declarator is a declaration and not a definition, its paramet

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

2025-04-28 Thread Erich Keane via cfe-commits
https://github.com/erichkeane commented: sorry! I made these comments a while ago, but apparently never submitted them. https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/

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

2025-04-28 Thread Erich Keane via cfe-commits
https://github.com/erichkeane edited https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-04-28 Thread Erich Keane via cfe-commits
@@ -6107,6 +6109,29 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) { + if (!II) +return false; + + // Build a static map of

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

2025-04-25 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: > > > But the token kind we have is `identifier` and not one of the keywords, > > > so we can't do the more trivial integer comparisons. > > > > > > Can we precompute a list/map/whatever of all identifiers that are keywords > > in C++ but not in C and then do pointer compa

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

2025-04-25 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/11] [C] Diagnose use of C++ keywords in C This adds a ne

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

2025-04-25 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/10] [C] Diagnose use of C++ keywords in C This adds a ne

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

2025-04-25 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 1/9] [C] Diagnose use of C++ keywords in C This adds a new

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

2025-04-25 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: > > But the token kind we have is `identifier` and not one of the keywords, so > > we can't do the more trivial integer comparisons. > > Can we precompute a list/map/whatever of all identifiers that are keywords in > C++ but not in C and then do pointer comparisons on the `

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

2025-04-25 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman edited https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-04-25 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 1/8] [C] Diagnose use of C++ keywords in C This adds a new

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

2025-04-25 Thread via cfe-commits
Sirraide wrote: > But the token kind we have is `identifier` and not one of the keywords, so we > can't do the more trivial integer comparisons. Can we precompute a list/map/whatever of all identifiers that are keywords in C++ but not in C and then do pointer comparisons on the `IdentifierInfo

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

2025-04-25 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: > What about `and`, `or`, and friends (which I think are only keywords in C if > you include a certain header irrc). Good call, I'll add those. https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-comm

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

2025-04-25 Thread Aaron Ballman via cfe-commits
@@ -0,0 +1,213 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Widentifier-is-c++-keyword %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wc++-compat %s +// RUN: %clang_cc1 -fsyntax-only -verify=good %s +// RUN: %clang_cc1 -fsyntax-only -verify=cxx -x c++ -std=c++2c %s +// good-no-dia

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

2025-04-25 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: Alas, I think this PR may be a non-starter due to performance: https://llvm-compile-time-tracker.com/?config=Overview&stat=wall-time&remote=AaronBallman: ``` C 56a3f3cd28 8.04s (+2.96%) 8.23s (+3.32%) 11.87s (+1.92%) 2.83s (+10.21%) 8.50s

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

2025-04-24 Thread via cfe-commits
https://github.com/Sirraide commented: What about `and`, `or`, and friends (which I think are only keywords in C if you include a certain header irrc). https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llv

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

2025-04-24 Thread via cfe-commits
Sirraide wrote: > I think `-Wc++-keyword` is kinda nice +1 https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-04-24 Thread Nikolas Klauser via cfe-commits
philnik777 wrote: > > Maybe `-Wkeyword-in-c++` or `-Wc++-keyword` would be a more concise name > > for the group? > > I'm not tied to the name I picked, so either of these is fine by me. GCC > doesn't split this into its own warning group, so we've got some latitude. > > Any strong preference

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

2025-04-24 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: > Maybe `-Wkeyword-in-c++` or `-Wc++-keyword` would be a more concise name for > the group? I'm not tied to the name I picked, so either of these is fine by me. GCC doesn't split this into its own warning group, so we've got some latitude. Any strong preferences? https://

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

2025-04-24 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 1/4] [C] Diagnose use of C++ keywords in C This adds a new

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

2025-04-24 Thread Nikolas Klauser via cfe-commits
philnik777 wrote: Maybe `-Wkeyword-in-c++` or `-Wc++-keyword` would be a more concise name for the group? https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/l

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

2025-04-24 Thread via cfe-commits
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff HEAD~1 HEAD --extensions cpp,c,h -- clang/test/Sema/c++-keyword-in-c.c clang/include/

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

2025-04-24 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: Note, I'm running this one through llvm-compile-time-tracker because of the lookup happening on every identifier. I'm not convinced that the "is this identifier a keyword in other language modes" code has good performance and wanted to double-check. https://github.com/llvm

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

2025-04-24 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 1/3] [C] Diagnose use of C++ keywords in C This adds a new

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

2025-04-24 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang Author: Aaron Ballman (AaronBallman) Changes This adds a new diagnostic group, -Widentifier-is-c++-keyword, which is off by default and grouped under -Wc++-compat. The diagnostic catches use of C++ keywords in C code. This change additionally fi

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

2025-04-24 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman created https://github.com/llvm/llvm-project/pull/137234 This adds a new diagnostic group, -Widentifier-is-c++-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