[clang-tidy] Ignore non-forwarded arguments if they are unused (#87832)
This commit is contained in:
parent
eb26edbbf8
commit
16b3e43a03
@ -9,8 +9,8 @@
|
||||
#include "MissingStdForwardCheck.h"
|
||||
#include "../utils/Matchers.h"
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/ExprConcepts.h"
|
||||
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
||||
#include "clang/Basic/IdentifierTable.h"
|
||||
|
||||
using namespace clang::ast_matchers;
|
||||
|
||||
@ -79,6 +79,11 @@ AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) {
|
||||
return Node.getCaptureDefault() == Kind;
|
||||
}
|
||||
|
||||
AST_MATCHER(VarDecl, hasIdentifier) {
|
||||
const IdentifierInfo *ID = Node.getIdentifier();
|
||||
return ID != NULL && !ID->isPlaceholder();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) {
|
||||
@ -125,12 +130,14 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) {
|
||||
hasAncestor(expr(hasUnevaluatedContext())))));
|
||||
|
||||
Finder->addMatcher(
|
||||
parmVarDecl(parmVarDecl().bind("param"), isTemplateTypeParameter(),
|
||||
hasAncestor(functionDecl().bind("func")),
|
||||
hasAncestor(functionDecl(
|
||||
isDefinition(), equalsBoundNode("func"), ToParam,
|
||||
unless(anyOf(isDeleted(), hasDescendant(std::move(
|
||||
ForwardCallMatcher))))))),
|
||||
parmVarDecl(
|
||||
parmVarDecl().bind("param"), hasIdentifier(),
|
||||
unless(hasAttr(attr::Kind::Unused)), isTemplateTypeParameter(),
|
||||
hasAncestor(functionDecl().bind("func")),
|
||||
hasAncestor(functionDecl(
|
||||
isDefinition(), equalsBoundNode("func"), ToParam,
|
||||
unless(anyOf(isDeleted(),
|
||||
hasDescendant(std::move(ForwardCallMatcher))))))),
|
||||
this);
|
||||
}
|
||||
|
||||
|
@ -179,8 +179,9 @@ Changes in existing checks
|
||||
|
||||
- Improved :doc:`cppcoreguidelines-missing-std-forward
|
||||
<clang-tidy/checks/cppcoreguidelines/missing-std-forward>` check by no longer
|
||||
giving false positives for deleted functions and fix false negative when some
|
||||
parameters are forwarded, but other aren't.
|
||||
giving false positives for deleted functions, by fixing false negatives when only
|
||||
a few parameters are forwarded and by ignoring parameters without a name (unused
|
||||
arguments).
|
||||
|
||||
- Improved :doc:`cppcoreguidelines-owning-memory
|
||||
<clang-tidy/checks/cppcoreguidelines/owning-memory>` check to properly handle
|
||||
|
@ -198,3 +198,16 @@ struct S {
|
||||
};
|
||||
|
||||
} // namespace deleted_functions
|
||||
|
||||
namespace unused_arguments {
|
||||
|
||||
template<typename F>
|
||||
void unused_argument1(F&&) {}
|
||||
|
||||
template<typename F>
|
||||
void unused_argument2([[maybe_unused]] F&& f) {}
|
||||
|
||||
template<typename F>
|
||||
void unused_argument3(F&& _) {}
|
||||
|
||||
} // namespace unused_arguments
|
||||
|
Loading…
x
Reference in New Issue
Block a user