[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 28 08:44:45 PDT 2025
================
@@ -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 parameters
+ // will not be pushed onto a scope chain. That means we will not issue any
+ // reserved identifier warnings for the declaration, but we will for the
+ // definition. Handle those here.
+ if (!Params.empty() && !D.isFunctionDefinition()) {
----------------
AaronBallman wrote:
They're tested:
```
// Smoke test that we catch keyword use in function parameters too.
void func(int private); // expected-warning {{identifier 'private' conflicts with a C++ keyword}} \
cxx-error {{invalid parameter name: 'private' is a keyword}}
```
around line 192
https://github.com/llvm/llvm-project/pull/137234
More information about the cfe-commits
mailing list