17 return Node.isIntegerType() && !
Node.isAnyCharacterType() &&
18 !
Node.isBooleanType();
25 hasDeclaration(functionDecl(
26 returns(hasDeclaration(classTemplateSpecializationDecl(
27 hasName(
"std::basic_string"),
28 hasTemplateArgument(0,
29 templateArgument().bind(
"char_type"))))),
30 hasName(
"boost::lexical_cast"),
31 hasParameter(0, hasType(qualType(has(substTemplateTypeParmType(
32 isStrictlyInteger()))))))),
33 argumentCountIs(1), unless(isInTemplateInstantiation()))
39 const auto *Call = Result.Nodes.getNodeAs<CallExpr>(
"to_string");
41 Result.Nodes.getNodeAs<TemplateArgument>(
"char_type")->getAsType();
44 if (CharType->isSpecificBuiltinType(BuiltinType::Char_S) ||
45 CharType->isSpecificBuiltinType(BuiltinType::Char_U))
46 StringType =
"string";
47 else if (CharType->isSpecificBuiltinType(BuiltinType::WChar_S) ||
48 CharType->isSpecificBuiltinType(BuiltinType::WChar_U))
49 StringType =
"wstring";
53 auto Loc = Call->getBeginLoc();
55 diag(
Loc,
"use std::to_%0 instead of boost::lexical_cast<std::%0>")
61 Diag << FixItHint::CreateReplacement(
62 CharSourceRange::getCharRange(Call->getBeginLoc(),
63 Call->getArg(0)->getBeginLoc()),
64 (llvm::Twine(
"std::to_") + StringType +
"(").str());
::clang::DynTypedNode Node
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
AST_MATCHER(Decl, declHasNoReturnAttr)
matches a Decl if it has a "no return" attribute of any kind