[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
Tue Oct 31 22:51:52 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:

If so, what about adding an assertion in the original version of `DiagnoseUnusedParameters`? Or should we keep the interface as is (allowing coroutines to be diagnosed in the same function, but handle the special case in `DiagnoseUnusedParameters` without changing the interface?)

`CoroutineParameterMoves` does not give me what I want. It points me to `Stmt`s that moved the parameters while I need the opposite -- All other references to the parameters. 

https://github.com/llvm/llvm-project/pull/70567


More information about the cfe-commits mailing list