[clang] [Clang] Warn against unused parameters in C++ coroutines with `-Wunused-parameters` (PR #70567)
Yuxuan Chen via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 1 00:32:54 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);
----------------
yuxuanchen1997 wrote:
> Sorry, what do you mean by adding an assertion to DiagnoseUnusedParameters? Do you say doing so after adopting my suggest? Then, it sounds good but how can we do that? And it sounds not meaningful.
I didn't make it clear. I was asking what you may think about an assertion in DiagnoseUnusedParameters that !CurFunction()->isCoroutine()
> An instinct idea now is to mark all the parameters as non referenced/used after building CoroutineParameterMoves. But it needs to be verified.
New to clang so I can't tell if I did something wrong. But the compiler crashed when I initially tried that.
I have to sign off now. Catch up with you soon.
https://github.com/llvm/llvm-project/pull/70567
More information about the cfe-commits
mailing list