Skip to content

Commit 3b0732e

Browse files
committed
Fix the parameter handling
1 parent 56a3f3c commit 3b0732e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ Improvements to Clang's diagnostics
419419
- ``-Winitializer-overrides`` and ``-Wreorder-init-list`` are now grouped under
420420
the ``-Wc99-designator`` diagnostic group, as they also are about the
421421
behavior of the C99 feature as it was introduced into C++20. Fixes #GH47037
422+
- ``-Wreserved-identifier`` now fires on reserved parameter names in a function
423+
declaration which is not a definition.
422424

423425
Improvements to Clang's time-trace
424426
----------------------------------

clang/lib/Sema/SemaDecl.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10438,6 +10438,15 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1043810438
// Finally, we know we have the right number of parameters, install them.
1043910439
NewFD->setParams(Params);
1044010440

10441+
// If this declarator is a declaration and not a definition, its parameters
10442+
// will not be pushed onto a scope chain. That means we will not issue any
10443+
// reserved identifier warnings for the declaration, but we will for the
10444+
// definition. Handle those here.
10445+
if (!Params.empty() && !D.isFunctionDefinition()) {
10446+
for (const ParmVarDecl *PVD : Params)
10447+
warnOnReservedIdentifier(PVD);
10448+
}
10449+
1044110450
if (D.getDeclSpec().isNoreturnSpecified())
1044210451
NewFD->addAttr(
1044310452
C11NoReturnAttr::Create(Context, D.getDeclSpec().getNoreturnSpecLoc()));
@@ -15333,7 +15342,6 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator &D,
1533315342
if (D.isInvalidType())
1533415343
New->setInvalidDecl();
1533515344

15336-
warnOnReservedIdentifier(New);
1533715345
CheckExplicitObjectParameter(*this, New, ExplicitThisLoc);
1533815346

1533915347
assert(S->isFunctionPrototypeScope());

0 commit comments

Comments
 (0)