10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
12 #include "clang/Lex/Lexer.h"
21 const auto DurationExpr =
22 expr(hasType(cxxRecordDecl(hasName(
"::absl::Duration"))));
24 traverse(ast_type_traits::TK_AsIs,
26 hasSourceExpression(ignoringParenCasts(
27 cxxOperatorCallExpr(hasOverloadedOperatorName(
"/"),
28 hasArgument(0, DurationExpr),
29 hasArgument(1, DurationExpr))
31 hasImplicitDestinationType(qualType(unless(isInteger()))),
32 unless(hasParent(cxxStaticCastExpr())),
33 unless(hasParent(cStyleCastExpr())),
34 unless(isInTemplateInstantiation()))),
39 const auto *OpCall = result.Nodes.getNodeAs<CXXOperatorCallExpr>(
"OpCall");
40 diag(OpCall->getOperatorLoc(),
41 "operator/ on absl::Duration objects performs integer division; "
42 "did you mean to use FDivDuration()?")
43 << FixItHint::CreateInsertion(OpCall->getBeginLoc(),
44 "absl::FDivDuration(")
45 << FixItHint::CreateReplacement(
46 SourceRange(OpCall->getOperatorLoc(), OpCall->getOperatorLoc()),
48 << FixItHint::CreateInsertion(
49 Lexer::getLocForEndOfToken(
50 result.SourceManager->getSpellingLoc(OpCall->getEndLoc()), 0,
51 *result.SourceManager, result.Context->getLangOpts()),