void UseToStringCheck::check(const MatchFinder::MatchResult &Result) {
  const auto *Call = Result.Nodes.getNodeAs<CallExpr>("to_string");
  auto CharType =
      Result.Nodes.getNodeAs<TemplateArgument>("char_type")->getAsType();

  StringRef StringType;
  if (CharType->isSpecificBuiltinType(BuiltinType::Char_S) ||
      CharType->isSpecificBuiltinType(BuiltinType::Char_U))
    StringType = "string";
  else if (CharType->isSpecificBuiltinType(BuiltinType::WChar_S) ||
           CharType->isSpecificBuiltinType(BuiltinType::WChar_U))
    StringType = "wstring";
  else
    return;

  auto Loc = Call->getLocStart();
  auto Diag =
      diag(Loc, "use std::to_%0 instead of boost::lexical_cast<std::%0>")
      << StringType;

  if (Loc.isMacroID())
    return;

  Diag << FixItHint::CreateReplacement(
      CharSourceRange::getCharRange(Call->getLocStart(),
                                    Call->getArg(0)->getExprLoc()),
      (llvm::Twine("std::to_") + StringType + "(").str());
}
Пример #2
0
 void PtrCastWinChecker::checkPreStmt(const clang::CStyleCastExpr* CE, clang::ento::CheckerContext& C) const
 {
    if (clang::CK_PointerToIntegral != CE->getCastKind()) return;
    auto subExpr = CE->getSubExpr();
    auto& Ctx = C.getASTContext();
    clang::QualType fromQType = Ctx.getCanonicalType(subExpr->getType());
    clang::QualType toQType = Ctx.getCanonicalType(CE->getType());
    if (fromQType->isPointerType() || fromQType->isArrayType()) {
       auto toType = toQType.getTypePtr();
       // Case one: the toType is a builtin and not a long long
       if (toType->isSpecificBuiltinType(clang::BuiltinType::Long) ||
           toType->isSpecificBuiltinType(clang::BuiltinType::ULong)){
           std::string r = "[sas.CodingConventions.ROOT.PtrCastWinChecker] Casting pointers to integer types which are not (unsigned) long long (in this case a ";
           r+=toQType.getAsString ();
           r+=") is wrong on Windows 64 bits. ";
           Report(CE, r.c_str(), C);
       }
    }
 }