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

John McCall via cfe-commits cfe-commits at lists.llvm.org
Thu May 1 15:20:49 PDT 2025


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 names in the corresponding versions of Objective-C++ (but presumably should -- I wonder if we should just check whether the token has an identifier spelling and not care what kind it is, [like we do for attribute names](https://github.com/llvm/llvm-project/blob/c3715ecb1e1e63856a029be3c95b7e9595a56018/clang/lib/Parse/ParseDeclCXX.cpp#L4575)?).

Yeah, I can't think of any good reason why this has a hardcoded list of keywords. Even if it's desirable for switching purposes, seems like it should be autogenerated from `TokenKinds.def`.

> I wonder if it'd suffice to do a single-token lookahead / lookbehind in Objective-C / Objective-C++ and disable all of these warnings if the previous token is `@` or the next token is `:`

Sadly, nullary selector pieces aren't followed by colons: `[foo decltype]`, etc.

> I've removed support for Objective-C for now; we can come back to it again in the future.

I think that's fine.

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


More information about the cfe-commits mailing list