19 return Node.isIntegerType() && !Node.isAnyCharacterType() &&
20 !Node.isBooleanType();
24 void UseToStringCheck::registerMatchers(MatchFinder *Finder) {
27 hasDeclaration(functionDecl(
28 returns(hasDeclaration(classTemplateSpecializationDecl(
29 hasName(
"std::basic_string"),
30 hasTemplateArgument(0,
31 templateArgument().bind(
"char_type"))))),
32 hasName(
"boost::lexical_cast"),
33 hasParameter(0, hasType(qualType(has(substTemplateTypeParmType(
34 isStrictlyInteger()))))))),
35 argumentCountIs(1), unless(isInTemplateInstantiation()))
40 void UseToStringCheck::check(
const MatchFinder::MatchResult &Result) {
41 const auto *Call = Result.Nodes.getNodeAs<CallExpr>(
"to_string");
43 Result.Nodes.getNodeAs<TemplateArgument>(
"char_type")->getAsType();
46 if (
CharType->isSpecificBuiltinType(BuiltinType::Char_S) ||
47 CharType->isSpecificBuiltinType(BuiltinType::Char_U))
48 StringType =
"string";
49 else if (
CharType->isSpecificBuiltinType(BuiltinType::WChar_S) ||
50 CharType->isSpecificBuiltinType(BuiltinType::WChar_U))
51 StringType =
"wstring";
55 auto Loc = Call->getBeginLoc();
57 diag(
Loc,
"use std::to_%0 instead of boost::lexical_cast<std::%0>")
63 Diag << FixItHint::CreateReplacement(
64 CharSourceRange::getCharRange(Call->getBeginLoc(),
65 Call->getArg(0)->getBeginLoc()),
66 (llvm::Twine(
"std::to_") + StringType +
"(").str());