diff options
author | Alexander Kornienko <alexfh@google.com> | 2018-07-26 13:13:54 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2018-07-26 13:13:54 +0000 |
commit | a92c9ad17aed52e9c0656578213e35a6546d09a7 (patch) | |
tree | aa6a7e1ddec81b6fb45ec0de4982cfc7972523d5 | |
parent | 9c5eb38c5f15d7c61f46d5a5cf068380427a7eb3 (diff) |
[clang-tidy] Fix llvm.org/PR38315 (support type aliases in modernize-shrink-to-fit)
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@338025 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | clang-tidy/modernize/ShrinkToFitCheck.cpp | 4 | ||||
-rw-r--r-- | test/clang-tidy/modernize-shrink-to-fit.cpp | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/clang-tidy/modernize/ShrinkToFitCheck.cpp b/clang-tidy/modernize/ShrinkToFitCheck.cpp index ef920182..f197399b 100644 --- a/clang-tidy/modernize/ShrinkToFitCheck.cpp +++ b/clang-tidy/modernize/ShrinkToFitCheck.cpp @@ -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")), diff --git a/test/clang-tidy/modernize-shrink-to-fit.cpp b/test/clang-tidy/modernize-shrink-to-fit.cpp index f4f3388a..6993d300 100644 --- a/test/clang-tidy/modernize-shrink-to-fit.cpp +++ b/test/clang-tidy/modernize-shrink-to-fit.cpp @@ -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();{{$}} +} |