Mercurial > hg > CbC > CbC_llvm
diff clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp @ 221:79ff65ed7e25
LLVM12 Original
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Jun 2021 19:15:29 +0900 |
parents | 0572611fdcc8 |
children | 1f2b6ac9f198 |
line wrap: on
line diff
--- a/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp Tue Jun 15 19:13:43 2021 +0900 +++ b/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp Tue Jun 15 19:15:29 2021 +0900 @@ -92,16 +92,18 @@ callee(memberExpr().bind("member")), callee(cxxMethodDecl(hasAnyName("c_str", "data")))) .bind("call"); - + const auto HasRValueTempParent = + hasParent(materializeTemporaryExpr(unless(isBoundToLValue()))); // Detect redundant 'c_str()' calls through a string constructor. // If CxxConstructExpr is the part of some CallExpr we need to // check that matched ParamDecl of the ancestor CallExpr is not rvalue. Finder->addMatcher( - traverse(ast_type_traits::TK_AsIs, - cxxConstructExpr(StringConstructorExpr, - hasArgument(0, StringCStrCallExpr), - unless(hasParent(materializeTemporaryExpr( - unless(isBoundToLValue())))))), + traverse( + TK_AsIs, + cxxConstructExpr( + StringConstructorExpr, hasArgument(0, StringCStrCallExpr), + unless(anyOf(HasRValueTempParent, hasParent(cxxBindTemporaryExpr( + HasRValueTempParent)))))), this); // Detect: 's == str.c_str()' -> 's == str' @@ -156,7 +158,7 @@ // Detect redundant 'c_str()' calls through a StringRef constructor. Finder->addMatcher( traverse( - ast_type_traits::TK_AsIs, + TK_AsIs, cxxConstructExpr( // Implicit constructors of these classes are overloaded // wrt. string types and they internally make a StringRef