[clang-tools-extra] [clang-tidy] Fix misc-unused-parameters on params with attrs (PR #122286)

Maksim Ivanov via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 9 08:54:35 PST 2025


================
@@ -26,6 +29,17 @@ bool isOverrideMethod(const FunctionDecl *Function) {
     return MD->size_overridden_methods() > 0 || MD->hasAttr<OverrideAttr>();
   return false;
 }
+
+bool hasAttrAfterParam(const SourceManager *SourceManager,
+                       const ParmVarDecl *Param) {
+  for (const auto *Attr : Param->attrs()) {
+    if (SourceManager->isBeforeInTranslationUnit(Param->getLocation(),
+                                                 Attr->getLocation())) {
+      return true;
+    }
+  }
+  return false;
+}
----------------
emaxx-google wrote:

I've run this example, and with my CL clang-tidy comments out the argument in the `ANNOTATE_BEFORE` case, while leaving the `ANNOTATE_AFTER` case as-is. Is that incorrect? In the former case, the grammar makes the attribute apply to the (unnamed) parameter. I've also verified the clang built with #118501 doesn't complain on this.

But maybe I'm missing some other problem?..

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


More information about the cfe-commits mailing list