forked from OSchip/llvm-project
[clang-tidy] Fix naming convention in modernize-use-emplace
Summary: Conform to the llvm naming convention for local variables in modernize-use-emplace check. Reviewers: Prazek, JonasToth, alexfh Reviewed By: Prazek, JonasToth, alexfh Subscribers: cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32678 llvm-svn: 301780
This commit is contained in:
parent
ecbd57e98a
commit
57fa1de516
|
@ -45,7 +45,7 @@ void UseEmplaceCheck::registerMatchers(MatchFinder *Finder) {
|
||||||
// because this requires special treatment (it could cause performance
|
// because this requires special treatment (it could cause performance
|
||||||
// regression)
|
// regression)
|
||||||
// + match for emplace calls that should be replaced with insertion
|
// + match for emplace calls that should be replaced with insertion
|
||||||
auto callPushBack = cxxMemberCallExpr(
|
auto CallPushBack = cxxMemberCallExpr(
|
||||||
hasDeclaration(functionDecl(hasName("push_back"))),
|
hasDeclaration(functionDecl(hasName("push_back"))),
|
||||||
on(hasType(cxxRecordDecl(hasAnyName(SmallVector<StringRef, 5>(
|
on(hasType(cxxRecordDecl(hasAnyName(SmallVector<StringRef, 5>(
|
||||||
ContainersWithPushBack.begin(), ContainersWithPushBack.end()))))));
|
ContainersWithPushBack.begin(), ContainersWithPushBack.end()))))));
|
||||||
|
@ -54,38 +54,38 @@ void UseEmplaceCheck::registerMatchers(MatchFinder *Finder) {
|
||||||
// if emplacement fails (f.e. bad_alloc in vector) we will have leak of
|
// if emplacement fails (f.e. bad_alloc in vector) we will have leak of
|
||||||
// passed pointer because smart pointer won't be constructed
|
// passed pointer because smart pointer won't be constructed
|
||||||
// (and destructed) as in push_back case.
|
// (and destructed) as in push_back case.
|
||||||
auto isCtorOfSmartPtr = hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
|
auto IsCtorOfSmartPtr = hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
|
||||||
SmallVector<StringRef, 5>(SmartPointers.begin(), SmartPointers.end())))));
|
SmallVector<StringRef, 5>(SmartPointers.begin(), SmartPointers.end())))));
|
||||||
|
|
||||||
// Bitfields binds only to consts and emplace_back take it by universal ref.
|
// Bitfields binds only to consts and emplace_back take it by universal ref.
|
||||||
auto bitFieldAsArgument = hasAnyArgument(
|
auto BitFieldAsArgument = hasAnyArgument(
|
||||||
ignoringImplicit(memberExpr(hasDeclaration(fieldDecl(isBitField())))));
|
ignoringImplicit(memberExpr(hasDeclaration(fieldDecl(isBitField())))));
|
||||||
|
|
||||||
// Initializer list can't be passed to universal reference.
|
// Initializer list can't be passed to universal reference.
|
||||||
auto initializerListAsArgument = hasAnyArgument(
|
auto InitializerListAsArgument = hasAnyArgument(
|
||||||
ignoringImplicit(cxxConstructExpr(isListInitialization())));
|
ignoringImplicit(cxxConstructExpr(isListInitialization())));
|
||||||
|
|
||||||
// We could have leak of resource.
|
// We could have leak of resource.
|
||||||
auto newExprAsArgument = hasAnyArgument(ignoringImplicit(cxxNewExpr()));
|
auto NewExprAsArgument = hasAnyArgument(ignoringImplicit(cxxNewExpr()));
|
||||||
// We would call another constructor.
|
// We would call another constructor.
|
||||||
auto constructingDerived =
|
auto ConstructingDerived =
|
||||||
hasParent(implicitCastExpr(hasCastKind(CastKind::CK_DerivedToBase)));
|
hasParent(implicitCastExpr(hasCastKind(CastKind::CK_DerivedToBase)));
|
||||||
|
|
||||||
// emplace_back can't access private constructor.
|
// emplace_back can't access private constructor.
|
||||||
auto isPrivateCtor = hasDeclaration(cxxConstructorDecl(isPrivate()));
|
auto IsPrivateCtor = hasDeclaration(cxxConstructorDecl(isPrivate()));
|
||||||
|
|
||||||
auto hasInitList = has(ignoringImplicit(initListExpr()));
|
auto HasInitList = has(ignoringImplicit(initListExpr()));
|
||||||
// FIXME: Discard 0/NULL (as nullptr), static inline const data members,
|
// FIXME: Discard 0/NULL (as nullptr), static inline const data members,
|
||||||
// overloaded functions and template names.
|
// overloaded functions and template names.
|
||||||
auto soughtConstructExpr =
|
auto SoughtConstructExpr =
|
||||||
cxxConstructExpr(
|
cxxConstructExpr(
|
||||||
unless(anyOf(isCtorOfSmartPtr, hasInitList, bitFieldAsArgument,
|
unless(anyOf(IsCtorOfSmartPtr, HasInitList, BitFieldAsArgument,
|
||||||
initializerListAsArgument, newExprAsArgument,
|
InitializerListAsArgument, NewExprAsArgument,
|
||||||
constructingDerived, isPrivateCtor)))
|
ConstructingDerived, IsPrivateCtor)))
|
||||||
.bind("ctor");
|
.bind("ctor");
|
||||||
auto hasConstructExpr = has(ignoringImplicit(soughtConstructExpr));
|
auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
|
||||||
|
|
||||||
auto makePair = ignoringImplicit(
|
auto MakePair = ignoringImplicit(
|
||||||
callExpr(callee(expr(ignoringImplicit(
|
callExpr(callee(expr(ignoringImplicit(
|
||||||
declRefExpr(unless(hasExplicitTemplateArgs()),
|
declRefExpr(unless(hasExplicitTemplateArgs()),
|
||||||
to(functionDecl(hasName("::std::make_pair"))))
|
to(functionDecl(hasName("::std::make_pair"))))
|
||||||
|
@ -93,15 +93,15 @@ void UseEmplaceCheck::registerMatchers(MatchFinder *Finder) {
|
||||||
|
|
||||||
// make_pair can return type convertible to container's element type.
|
// make_pair can return type convertible to container's element type.
|
||||||
// Allow the conversion only on containers of pairs.
|
// Allow the conversion only on containers of pairs.
|
||||||
auto makePairCtor = ignoringImplicit(cxxConstructExpr(
|
auto MakePairCtor = ignoringImplicit(cxxConstructExpr(
|
||||||
has(materializeTemporaryExpr(makePair)),
|
has(materializeTemporaryExpr(MakePair)),
|
||||||
hasDeclaration(cxxConstructorDecl(ofClass(hasName("::std::pair"))))));
|
hasDeclaration(cxxConstructorDecl(ofClass(hasName("::std::pair"))))));
|
||||||
|
|
||||||
auto soughtParam = materializeTemporaryExpr(
|
auto SoughtParam = materializeTemporaryExpr(
|
||||||
anyOf(has(makePair), has(makePairCtor),
|
anyOf(has(MakePair), has(MakePairCtor),
|
||||||
hasConstructExpr, has(cxxFunctionalCastExpr(hasConstructExpr))));
|
HasConstructExpr, has(cxxFunctionalCastExpr(HasConstructExpr))));
|
||||||
|
|
||||||
Finder->addMatcher(cxxMemberCallExpr(callPushBack, has(soughtParam),
|
Finder->addMatcher(cxxMemberCallExpr(CallPushBack, has(SoughtParam),
|
||||||
unless(isInTemplateInstantiation()))
|
unless(isInTemplateInstantiation()))
|
||||||
.bind("call"),
|
.bind("call"),
|
||||||
this);
|
this);
|
||||||
|
|
Loading…
Reference in New Issue