diff options
author | Congcong Cai <congcongcai0907@163.com> | 2024-02-13 18:00:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-13 18:00:11 +0800 |
commit | ebe77cc320a1bcc8e2cec44f4f388fb43b72016d (patch) | |
tree | 7d2345d857d259bf5531f1d3fa288cf36b38ef69 /clang-tools-extra | |
parent | ca61e6a71dbe622593b27ab6c6f3bfd058069772 (diff) | |
download | llvm-ebe77cc320a1bcc8e2cec44f4f388fb43b72016d.zip llvm-ebe77cc320a1bcc8e2cec44f4f388fb43b72016d.tar.gz llvm-ebe77cc320a1bcc8e2cec44f4f388fb43b72016d.tar.bz2 |
[clang-tidy] ignore local variable with [maybe_unused] attribute in bugprone-unused-local-non-trivial-variable (#81563)
Diffstat (limited to 'clang-tools-extra')
4 files changed, 7 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp index 1b763d2..37baae7 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp @@ -60,6 +60,7 @@ void UnusedLocalNonTrivialVariableCheck::registerMatchers(MatchFinder *Finder) { varDecl(isLocalVarDecl(), unless(isReferenced()), unless(isExceptionVariable()), hasLocalStorage(), isDefinition(), unless(hasType(isReferenceType())), unless(hasType(isTrivial())), + unless(hasAttr(attr::Kind::Unused)), hasType(hasUnqualifiedDesugaredType( anyOf(recordType(hasDeclaration(namedDecl( matchesAnyListedName(IncludeTypes), diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index ee68c8f..f2fba9a 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -121,6 +121,10 @@ Changes in existing checks <clang-tidy/checks/bugprone/too-small-loop-variable>` check by incorporating better support for ``const`` loop boundaries. +- Improved :doc:`bugprone-unused-local-non-trivial-variable + <clang-tidy/checks/bugprone/unused-local-non-trivial-variable>` check by + ignoring local variable with ``[maybe_unused]`` attribute. + - Cleaned up :doc:`cppcoreguidelines-prefer-member-initializer <clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` by removing enforcement of rule `C.48 diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.rst index 7531f19..9f283de 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.rst @@ -11,6 +11,7 @@ The following types of variables are excluded from this check: * exception variables in catch clauses * static or thread local * structured bindings +* variables with ``[[maybe_unused]]`` attribute This check can be configured to warn on all non-trivial variables by setting `IncludeTypes` to `.*`, and excluding specific types using `ExcludeTypes`. diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp index 19f2344..3fdc24b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp @@ -77,6 +77,7 @@ T qux(T Generic) { // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: unused local variable 'TemplateType' of type 'async::Future<T>' [bugprone-unused-local-non-trivial-variable] a::Future<T> AliasTemplateType; // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: unused local variable 'AliasTemplateType' of type 'a::Future<T>' (aka 'Future<type-parameter-0-0>') [bugprone-unused-local-non-trivial-variable] + [[maybe_unused]] async::Future<Units> MaybeUnused; return Generic; } |