Skip to content

Commit

Permalink
[clang-tidy] Made abseil-faster-strsplit-delimiter tests pass on C++17
Browse files Browse the repository at this point in the history
Reviewers: hokein, gribozavr

Reviewed By: hokein, gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63253

Patch by Johan Vikström.

llvm-svn: 363273
  • Loading branch information
gribozavr committed Jun 13, 2019
1 parent 0030306 commit 558369b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ namespace {

AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }

::internal::Matcher<Expr>
constructExprWithArg(llvm::StringRef ClassName,
const ::internal::Matcher<Expr> &Arg) {
auto ConstrExpr = cxxConstructExpr(hasType(recordDecl(hasName(ClassName))),
hasArgument(0, ignoringParenCasts(Arg)));

return anyOf(ConstrExpr, cxxBindTemporaryExpr(has(ConstrExpr)));
}

::internal::Matcher<Expr>
copyConstructExprWithArg(llvm::StringRef ClassName,
const ::internal::Matcher<Expr> &Arg) {
return constructExprWithArg(ClassName, constructExprWithArg(ClassName, Arg));
}

llvm::Optional<std::string> makeCharacterLiteral(const StringLiteral *Literal) {
std::string Result;
{
Expand Down Expand Up @@ -74,11 +59,17 @@ void FasterStrsplitDelimiterCheck::registerMatchers(MatchFinder *Finder) {

// Binds to a string_view (either absl or std) that was passed by value and
// contructed from string literal.
auto StringViewArg =
copyConstructExprWithArg("::absl::string_view", SingleChar);
auto StringViewArg = ignoringElidableConstructorCall(ignoringImpCasts(
cxxConstructExpr(hasType(recordDecl(hasName("::absl::string_view"))),
hasArgument(0, ignoringParenImpCasts(SingleChar)))));

// Need to ignore the elidable constructor as otherwise there is no match for
// c++14 and earlier.
auto ByAnyCharArg =
expr(copyConstructExprWithArg("::absl::ByAnyChar", StringViewArg))
expr(has(ignoringElidableConstructorCall(
ignoringParenCasts(cxxBindTemporaryExpr(has(cxxConstructExpr(
hasType(recordDecl(hasName("::absl::ByAnyChar"))),
hasArgument(0, StringViewArg))))))))
.bind("ByAnyChar");

// Find uses of absl::StrSplit(..., "x") and absl::StrSplit(...,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-faster-strsplit-delimiter %t
// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-faster-strsplit-delimiter %t
// FIXME: Fix the checker to work in C++17 mode.

namespace absl {
Expand Down

0 comments on commit 558369b

Please sign in to comment.