diff --git a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp --- a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp @@ -29,16 +29,26 @@ static bool isConstructorAssignment(const MatchFinder::MatchResult &Result, const Expr *Node) { + // For C++14 and earlier there are elidable constructors that must be matched + // in hasParent. The elidable constructors do not exist in C++17 and later and + // therefore an additional check that does not match against the elidable + // constructors are needed for this case. return selectFirst( - "e", match(expr(hasParent(materializeTemporaryExpr(hasParent( - cxxConstructExpr(hasParent(exprWithCleanups( - hasParent(varDecl())))))))) - .bind("e"), - *Node, *Result.Context)) != nullptr; + "e", + match(callExpr(hasParent(materializeTemporaryExpr( + hasParent(cxxConstructExpr(hasParent( + exprWithCleanups(hasParent(varDecl())))))))) + .bind("e"), + *Node, *Result.Context)) != nullptr || + selectFirst("e", + match(callExpr(hasParent(varDecl())).bind("e"), + *Node, *Result.Context)) != nullptr; } static bool isArgument(const MatchFinder::MatchResult &Result, const Expr *Node) { + // For the same reason as in isConstructorAssignment two separate selectFirsts + // need to be checked here return selectFirst( "e", match(expr(hasParent( @@ -46,16 +56,26 @@ hasParent(callExpr()), unless(hasParent(cxxOperatorCallExpr()))))))) .bind("e"), - *Node, *Result.Context)) != nullptr; + *Node, *Result.Context)) != nullptr || + selectFirst( + "e", match(expr(hasParent(callExpr()), + unless(hasParent(cxxOperatorCallExpr()))) + .bind("e"), + *Node, *Result.Context)) != nullptr; } static bool isReturn(const MatchFinder::MatchResult &Result, const Expr *Node) { + // For the same reason as in isConstructorAssignment two separate selectFirsts + // need to be checked here return selectFirst( "e", match(expr(hasParent(materializeTemporaryExpr(hasParent( cxxConstructExpr(hasParent(exprWithCleanups( hasParent(returnStmt())))))))) .bind("e"), - *Node, *Result.Context)) != nullptr; + *Node, *Result.Context)) != nullptr || + selectFirst("e", + match(expr(hasParent(returnStmt())).bind("e"), + *Node, *Result.Context)) != nullptr; } static bool parensRequired(const MatchFinder::MatchResult &Result, diff --git a/clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp b/clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp --- a/clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp +++ b/clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-time-subtraction %t -- -- -I %S/Inputs +// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-time-subtraction %t -- -- -I %S/Inputs // FIXME: Fix the checker to work in C++17 mode. #include "absl/time/time.h"