[clang-tools-extra] [clang-tidy] Fix misc-unused-parameters on params with attrs (PR #122286)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 9 08:27:16 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;
+}
----------------
usx95 wrote:
It is unfortunate that for declaration attributes we do not have the information that attr appeared before or after the decl.
I would argue, for simplicity, we filter out all annotated params irrespective of the position of attribute.
Dealing with raw source locations can quickly become problematic. For example with expanded locations:
```cpp
#define ANNOTATE_BEFORE(x) [[clang::lifetimebound]] x
#define ANNOTATE_AFTER(x) x [[clang::lifetimebound]]
int* foo(ANNOTATE_BEFORE(int* x)) {}
int* bar(ANNOTATE_AFTER(int* x)) {}
```
https://godbolt.org/z/brYMKfcxf
It is possible to make it work but I don't see the point of this complexity when we can have a simpler filter without much fallout
https://github.com/llvm/llvm-project/pull/122286
More information about the cfe-commits
mailing list