[clang-tidy] Fix llvm.org/PR38315 (support type aliases in modernize-shrink-to-fit)

llvm-svn: 338025
This commit is contained in:
Alexander Kornienko 2018-07-26 13:13:54 +00:00
parent 1b58759d82
commit 7b6993d445
2 changed files with 15 additions and 2 deletions

View File

@ -43,8 +43,8 @@ void ShrinkToFitCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
cxxMemberCallExpr(
on(hasType(namedDecl(
hasAnyName("std::basic_string", "std::deque", "std::vector")))),
on(hasType(hasCanonicalType(hasDeclaration(namedDecl(
hasAnyName("std::basic_string", "std::deque", "std::vector")))))),
callee(cxxMethodDecl(hasName("swap"))),
has(ignoringParenImpCasts(memberExpr(hasDescendant(CopyCtorCall)))),
hasArgument(0, SwapParam.bind("ContainerToShrink")),

View File

@ -72,3 +72,16 @@ void h() {
// 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();{{$}}
}