forked from OSchip/llvm-project
[clang-tidy] Fix llvm.org/PR38315 (support type aliases in modernize-shrink-to-fit)
llvm-svn: 338025
This commit is contained in:
parent
1b58759d82
commit
7b6993d445
|
@ -43,8 +43,8 @@ void ShrinkToFitCheck::registerMatchers(MatchFinder *Finder) {
|
||||||
|
|
||||||
Finder->addMatcher(
|
Finder->addMatcher(
|
||||||
cxxMemberCallExpr(
|
cxxMemberCallExpr(
|
||||||
on(hasType(namedDecl(
|
on(hasType(hasCanonicalType(hasDeclaration(namedDecl(
|
||||||
hasAnyName("std::basic_string", "std::deque", "std::vector")))),
|
hasAnyName("std::basic_string", "std::deque", "std::vector")))))),
|
||||||
callee(cxxMethodDecl(hasName("swap"))),
|
callee(cxxMethodDecl(hasName("swap"))),
|
||||||
has(ignoringParenImpCasts(memberExpr(hasDescendant(CopyCtorCall)))),
|
has(ignoringParenImpCasts(memberExpr(hasDescendant(CopyCtorCall)))),
|
||||||
hasArgument(0, SwapParam.bind("ContainerToShrink")),
|
hasArgument(0, SwapParam.bind("ContainerToShrink")),
|
||||||
|
|
|
@ -72,3 +72,16 @@ void h() {
|
||||||
// CHECK-FIXES: {{^ }}COPY_AND_SWAP_INT_VEC(v);{{$}}
|
// CHECK-FIXES: {{^ }}COPY_AND_SWAP_INT_VEC(v);{{$}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PR38315() {
|
||||||
|
typedef std::vector<int> Vector;
|
||||||
|
Vector v;
|
||||||
|
Vector(v).swap(v);
|
||||||
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the shrink_to_fit method should
|
||||||
|
// CHECK-FIXES: {{^ }}v.shrink_to_fit();{{$}}
|
||||||
|
|
||||||
|
using Vector2 = std::vector<int>;
|
||||||
|
Vector2 v2;
|
||||||
|
Vector2(v2).swap(v2);
|
||||||
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the shrink_to_fit method should
|
||||||
|
// CHECK-FIXES: {{^ }}v2.shrink_to_fit();{{$}}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue