[clang] [Clang] disallow attributes on void parameters (PR #124920)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 31 05:44:29 PST 2025
================
@@ -10326,6 +10326,15 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
}
}
+ if (FTIHasSingleVoidParameter(FTI)) {
+ ParmVarDecl *Param = cast<ParmVarDecl>(FTI.Params[0].Param);
+ if (Param->hasAttrs()) {
+ for (const auto *A : Param->attrs())
+ Diag(A->getLoc(), diag::warn_attribute_on_void_param)
+ << A << A->getRange();
+ }
----------------
AaronBallman wrote:
```suggestion
for (const auto *A : Param->attrs())
Diag(A->getLoc(), diag::warn_attribute_on_void_param)
<< A << A->getRange();
```
I forgot that `attrs()` handles the no-attributes case gracefully (it's `getAttrs()` that doesn't), so we don't need the extra check.
https://github.com/llvm/llvm-project/pull/124920
More information about the cfe-commits
mailing list