[clang-tidy] Fix llvm.org/PR38315 (support type aliases in modernize-shrink-to-fit)
authorAlexander Kornienko <alexfh@google.com>
Thu, 26 Jul 2018 13:13:54 +0000 (13:13 +0000)
committerAlexander Kornienko <alexfh@google.com>
Thu, 26 Jul 2018 13:13:54 +0000 (13:13 +0000)
llvm-svn: 338025

clang-tools-extra/clang-tidy/modernize/ShrinkToFitCheck.cpp
clang-tools-extra/test/clang-tidy/modernize-shrink-to-fit.cpp

index ef92018..f197399 100644 (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")),
index f4f3388..6993d30 100644 (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();{{$}}
+}