[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
John McCall via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 30 11:30:29 PDT 2025
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 `ParseObjCSelectorPiece` and how it generally accepts keywords in the selector. Actually, the list of keywords there seems out of date and notably doesn't include post-C++98 keywords like `decltype`. The logic is absolutely meant to encompass every keyword; note that it even includes basic C keywords like `if` and `struct`. You probably don't want to fix that, but I can ping someone at Apple to do it.
Anyway, selectors show up in three places in the ObjC grammar:
- `@selector` expressions, e.g. `@selector(virtual:typeid:bool:)`
- message send expressions, e.g. `[obj virtual: 0 typeid: 0 bool: 0]`
- method declarations, e.g. `
- declarations, e.g.
```
@interface Foo
- (void) virtual: (int) x typeid: (int) y bool: (int) z;
@end
```
But there are also some special-case parsing rules for `class` because it is an important property name for `NSObject`. For example, in Objective-C++, the member name following `-> ` or `.` is allowed to be `class` despite it being a keyword.
https://github.com/llvm/llvm-project/pull/137234
More information about the cfe-commits
mailing list