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

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 26 06:13:54 PDT 2018


Author: alexfh
Date: Thu Jul 26 06:13:54 2018
New Revision: 338025

URL: http://llvm.org/viewvc/llvm-project?rev=338025&view=rev
Log:
[clang-tidy] Fix llvm.org/PR38315 (support type aliases in modernize-shrink-to-fit)

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

Modified: clang-tools-extra/trunk/clang-tidy/modernize/ShrinkToFitCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/ShrinkToFitCheck.cpp?rev=338025&r1=338024&r2=338025&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/ShrinkToFitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/ShrinkToFitCheck.cpp Thu Jul 26 06:13:54 2018
@@ -43,8 +43,8 @@ void ShrinkToFitCheck::registerMatchers(
 
   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")),

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-shrink-to-fit.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-shrink-to-fit.cpp?rev=338025&r1=338024&r2=338025&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-shrink-to-fit.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-shrink-to-fit.cpp Thu Jul 26 06:13:54 2018
@@ -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();{{$}}
+}




More information about the cfe-commits mailing list