[clang] [Clang] Warn against unused parameters in C++ coroutines with `-Wunused-parameters` (PR #70567)
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 31 22:18:06 PDT 2023
================
@@ -3165,7 +3165,16 @@ class Sema final {
/// Diagnose any unused parameters in the given sequence of
/// ParmVarDecl pointers.
- void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters);
+ ///
+ /// Normally, we check if the parameter decls have the Referenced bit set.
+ /// C++ Coroutines, however, are a special case due to the existences of
+ /// parameter moves (See Sema::buildCoroutineParameterMoves), the parameters
+ /// are always referenced in coroutines. Therefore, in the case of coroutines,
+ /// CoroutineBodyRefs must be passed to correctly diagnose parameter usages
+ /// as written by the user.
+ void DiagnoseUnusedParameters(
+ ArrayRef<ParmVarDecl *> Parameters,
+ llvm::SmallSet<ParmVarDecl *, 4> *CoroutineBodyRefs = nullptr);
----------------
ChuanqiXu9 wrote:
Let's try to not polluting the interfaces as much as possible. Since most of the functions are not coroutines, it looks not good to pollute the interfaces.
Personally, I prefer the style:
```
if (the function is coroutine)
DiagnoseUnusedParametersInCoroutines(...);
else
DiagnoseUnusedParameters(...); // Original call.
```
Also it may be better to use `FunctionScopeInfo::CoroutineParameterMoves` than yet another DeclsVisitor. It is easy prone and hard to maintain.
https://github.com/llvm/llvm-project/pull/70567
More information about the cfe-commits
mailing list