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")),
// 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();{{$}}
+}