2016-05-03 00:56:39 +08:00
|
|
|
//===--- MakeSmartPtrCheck.cpp - clang-tidy--------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MakeSharedCheck.h"
|
2017-07-05 15:49:00 +08:00
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
2016-05-03 00:56:39 +08:00
|
|
|
#include "clang/Lex/Lexer.h"
|
2017-07-05 15:49:00 +08:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2016-05-03 00:56:39 +08:00
|
|
|
|
|
|
|
using namespace clang::ast_matchers;
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace modernize {
|
|
|
|
|
2017-06-27 16:31:27 +08:00
|
|
|
namespace {
|
2017-07-05 15:49:00 +08:00
|
|
|
|
|
|
|
constexpr char StdMemoryHeader[] = "memory";
|
|
|
|
|
2017-06-28 00:25:05 +08:00
|
|
|
std::string GetNewExprName(const CXXNewExpr *NewExpr,
|
|
|
|
const SourceManager &SM,
|
|
|
|
const LangOptions &Lang) {
|
|
|
|
StringRef WrittenName = Lexer::getSourceText(
|
2017-06-27 16:31:27 +08:00
|
|
|
CharSourceRange::getTokenRange(
|
|
|
|
NewExpr->getAllocatedTypeSourceInfo()->getTypeLoc().getSourceRange()),
|
|
|
|
SM, Lang);
|
2017-06-28 00:25:05 +08:00
|
|
|
if (NewExpr->isArray()) {
|
|
|
|
return WrittenName.str() + "[]";
|
|
|
|
}
|
|
|
|
return WrittenName.str();
|
2017-06-27 16:31:27 +08:00
|
|
|
}
|
2017-07-05 15:49:00 +08:00
|
|
|
|
2017-06-27 16:31:27 +08:00
|
|
|
} // namespace
|
|
|
|
|
2016-05-03 00:56:39 +08:00
|
|
|
const char MakeSmartPtrCheck::PointerType[] = "pointerType";
|
|
|
|
const char MakeSmartPtrCheck::ConstructorCall[] = "constructorCall";
|
2016-10-31 23:48:01 +08:00
|
|
|
const char MakeSmartPtrCheck::ResetCall[] = "resetCall";
|
2016-05-03 00:56:39 +08:00
|
|
|
const char MakeSmartPtrCheck::NewExpression[] = "newExpression";
|
|
|
|
|
2017-08-04 19:18:00 +08:00
|
|
|
MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name,
|
|
|
|
ClangTidyContext* Context,
|
2017-07-05 15:49:00 +08:00
|
|
|
StringRef MakeSmartPtrFunctionName)
|
2016-05-03 00:56:39 +08:00
|
|
|
: ClangTidyCheck(Name, Context),
|
2017-07-05 15:49:00 +08:00
|
|
|
IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
|
2017-07-20 20:02:03 +08:00
|
|
|
Options.getLocalOrGlobal("IncludeStyle", "llvm"))),
|
2017-07-05 15:49:00 +08:00
|
|
|
MakeSmartPtrFunctionHeader(
|
|
|
|
Options.get("MakeSmartPtrFunctionHeader", StdMemoryHeader)),
|
|
|
|
MakeSmartPtrFunctionName(
|
2017-08-04 19:18:00 +08:00
|
|
|
Options.get("MakeSmartPtrFunction", MakeSmartPtrFunctionName)),
|
|
|
|
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
|
2017-07-05 15:49:00 +08:00
|
|
|
|
|
|
|
void MakeSmartPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
|
|
|
|
Options.store(Opts, "IncludeStyle", IncludeStyle);
|
|
|
|
Options.store(Opts, "MakeSmartPtrFunctionHeader", MakeSmartPtrFunctionHeader);
|
|
|
|
Options.store(Opts, "MakeSmartPtrFunction", MakeSmartPtrFunctionName);
|
2017-08-04 19:18:00 +08:00
|
|
|
Options.store(Opts, "IgnoreMacros", IgnoreMacros);
|
2017-07-05 15:49:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MakeSmartPtrCheck::registerPPCallbacks(CompilerInstance &Compiler) {
|
|
|
|
if (getLangOpts().CPlusPlus11) {
|
|
|
|
Inserter.reset(new utils::IncludeInserter(
|
|
|
|
Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
|
|
|
|
Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
|
|
|
|
}
|
|
|
|
}
|
2016-05-03 00:56:39 +08:00
|
|
|
|
|
|
|
void MakeSmartPtrCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
|
|
|
|
if (!getLangOpts().CPlusPlus11)
|
|
|
|
return;
|
|
|
|
|
2016-08-31 08:06:55 +08:00
|
|
|
// Calling make_smart_ptr from within a member function of a type with a
|
|
|
|
// private or protected constructor would be ill-formed.
|
2016-10-31 23:48:01 +08:00
|
|
|
auto CanCallCtor = unless(has(ignoringImpCasts(
|
|
|
|
cxxConstructExpr(hasDeclaration(decl(unless(isPublic())))))));
|
2016-08-31 08:06:55 +08:00
|
|
|
|
2016-05-03 00:56:39 +08:00
|
|
|
Finder->addMatcher(
|
2016-05-31 23:26:56 +08:00
|
|
|
cxxBindTemporaryExpr(has(ignoringParenImpCasts(
|
|
|
|
cxxConstructExpr(
|
|
|
|
hasType(getSmartPointerTypeMatcher()), argumentCountIs(1),
|
|
|
|
hasArgument(0,
|
|
|
|
cxxNewExpr(hasType(pointsTo(qualType(hasCanonicalType(
|
2016-08-31 08:06:55 +08:00
|
|
|
equalsBoundNode(PointerType))))),
|
|
|
|
CanCallCtor)
|
2017-08-17 22:12:38 +08:00
|
|
|
.bind(NewExpression)),
|
|
|
|
unless(isInTemplateInstantiation()))
|
2016-05-31 23:26:56 +08:00
|
|
|
.bind(ConstructorCall)))),
|
2016-05-03 00:56:39 +08:00
|
|
|
this);
|
2016-10-31 23:48:01 +08:00
|
|
|
|
|
|
|
Finder->addMatcher(
|
|
|
|
cxxMemberCallExpr(
|
|
|
|
thisPointerType(getSmartPointerTypeMatcher()),
|
|
|
|
callee(cxxMethodDecl(hasName("reset"))),
|
2017-08-17 22:12:38 +08:00
|
|
|
hasArgument(0, cxxNewExpr(CanCallCtor).bind(NewExpression)),
|
|
|
|
unless(isInTemplateInstantiation()))
|
2016-10-31 23:48:01 +08:00
|
|
|
.bind(ResetCall),
|
|
|
|
this);
|
2016-05-03 00:56:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MakeSmartPtrCheck::check(const MatchFinder::MatchResult &Result) {
|
|
|
|
// 'smart_ptr' refers to 'std::shared_ptr' or 'std::unique_ptr' or other
|
|
|
|
// pointer, 'make_smart_ptr' refers to 'std::make_shared' or
|
|
|
|
// 'std::make_unique' or other function that creates smart_ptr.
|
|
|
|
|
|
|
|
SourceManager &SM = *Result.SourceManager;
|
|
|
|
const auto *Construct =
|
|
|
|
Result.Nodes.getNodeAs<CXXConstructExpr>(ConstructorCall);
|
2016-10-31 23:48:01 +08:00
|
|
|
const auto *Reset = Result.Nodes.getNodeAs<CXXMemberCallExpr>(ResetCall);
|
2016-05-03 00:56:39 +08:00
|
|
|
const auto *Type = Result.Nodes.getNodeAs<QualType>(PointerType);
|
|
|
|
const auto *New = Result.Nodes.getNodeAs<CXXNewExpr>(NewExpression);
|
|
|
|
|
|
|
|
if (New->getNumPlacementArgs() != 0)
|
|
|
|
return;
|
|
|
|
|
2016-10-31 23:48:01 +08:00
|
|
|
if (Construct)
|
|
|
|
checkConstruct(SM, Construct, Type, New);
|
|
|
|
else if (Reset)
|
|
|
|
checkReset(SM, Reset, New);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MakeSmartPtrCheck::checkConstruct(SourceManager &SM,
|
|
|
|
const CXXConstructExpr *Construct,
|
|
|
|
const QualType *Type,
|
|
|
|
const CXXNewExpr *New) {
|
2016-05-03 00:56:39 +08:00
|
|
|
SourceLocation ConstructCallStart = Construct->getExprLoc();
|
2017-08-04 19:18:00 +08:00
|
|
|
bool InMacro = ConstructCallStart.isMacroID();
|
|
|
|
|
|
|
|
if (InMacro && IgnoreMacros) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-03 00:56:39 +08:00
|
|
|
|
|
|
|
bool Invalid = false;
|
|
|
|
StringRef ExprStr = Lexer::getSourceText(
|
|
|
|
CharSourceRange::getCharRange(
|
|
|
|
ConstructCallStart, Construct->getParenOrBraceRange().getBegin()),
|
2017-06-27 16:31:27 +08:00
|
|
|
SM, getLangOpts(), &Invalid);
|
2016-05-03 00:56:39 +08:00
|
|
|
if (Invalid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto Diag = diag(ConstructCallStart, "use %0 instead")
|
2017-07-05 15:49:00 +08:00
|
|
|
<< MakeSmartPtrFunctionName;
|
2016-05-03 00:56:39 +08:00
|
|
|
|
2017-08-04 19:18:00 +08:00
|
|
|
// Disable the fix in macros.
|
|
|
|
if (InMacro) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:14:52 +08:00
|
|
|
if (!replaceNew(Diag, New, SM)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-03 00:56:39 +08:00
|
|
|
// Find the location of the template's left angle.
|
|
|
|
size_t LAngle = ExprStr.find("<");
|
|
|
|
SourceLocation ConstructCallEnd;
|
|
|
|
if (LAngle == StringRef::npos) {
|
|
|
|
// If the template argument is missing (because it is part of the alias)
|
|
|
|
// we have to add it back.
|
|
|
|
ConstructCallEnd = ConstructCallStart.getLocWithOffset(ExprStr.size());
|
|
|
|
Diag << FixItHint::CreateInsertion(
|
2017-06-27 16:31:27 +08:00
|
|
|
ConstructCallEnd,
|
2017-06-28 00:25:05 +08:00
|
|
|
"<" + GetNewExprName(New, SM, getLangOpts()) + ">");
|
2016-05-03 00:56:39 +08:00
|
|
|
} else {
|
|
|
|
ConstructCallEnd = ConstructCallStart.getLocWithOffset(LAngle);
|
|
|
|
}
|
|
|
|
|
|
|
|
Diag << FixItHint::CreateReplacement(
|
|
|
|
CharSourceRange::getCharRange(ConstructCallStart, ConstructCallEnd),
|
2017-07-05 15:49:00 +08:00
|
|
|
MakeSmartPtrFunctionName);
|
2016-05-03 00:56:39 +08:00
|
|
|
|
|
|
|
// If the smart_ptr is built with brace enclosed direct initialization, use
|
|
|
|
// parenthesis instead.
|
|
|
|
if (Construct->isListInitialization()) {
|
|
|
|
SourceRange BraceRange = Construct->getParenOrBraceRange();
|
|
|
|
Diag << FixItHint::CreateReplacement(
|
|
|
|
CharSourceRange::getCharRange(
|
|
|
|
BraceRange.getBegin(), BraceRange.getBegin().getLocWithOffset(1)),
|
|
|
|
"(");
|
|
|
|
Diag << FixItHint::CreateReplacement(
|
|
|
|
CharSourceRange::getCharRange(BraceRange.getEnd(),
|
|
|
|
BraceRange.getEnd().getLocWithOffset(1)),
|
|
|
|
")");
|
|
|
|
}
|
|
|
|
|
2017-07-05 15:49:00 +08:00
|
|
|
insertHeader(Diag, SM.getFileID(ConstructCallStart));
|
2016-10-31 23:48:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MakeSmartPtrCheck::checkReset(SourceManager &SM,
|
|
|
|
const CXXMemberCallExpr *Reset,
|
|
|
|
const CXXNewExpr *New) {
|
|
|
|
const auto *Expr = cast<MemberExpr>(Reset->getCallee());
|
|
|
|
SourceLocation OperatorLoc = Expr->getOperatorLoc();
|
|
|
|
SourceLocation ResetCallStart = Reset->getExprLoc();
|
|
|
|
SourceLocation ExprStart = Expr->getLocStart();
|
|
|
|
SourceLocation ExprEnd =
|
|
|
|
Lexer::getLocForEndOfToken(Expr->getLocEnd(), 0, SM, getLangOpts());
|
|
|
|
|
2017-08-04 19:18:00 +08:00
|
|
|
bool InMacro = ExprStart.isMacroID();
|
|
|
|
|
|
|
|
if (InMacro && IgnoreMacros) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-10 01:03:42 +08:00
|
|
|
// There are some cases where we don't have operator ("." or "->") of the
|
|
|
|
// "reset" expression, e.g. call "reset()" method directly in the subclass of
|
|
|
|
// "std::unique_ptr<>". We skip these cases.
|
|
|
|
if (OperatorLoc.isInvalid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-31 23:48:01 +08:00
|
|
|
auto Diag = diag(ResetCallStart, "use %0 instead")
|
2017-07-05 15:49:00 +08:00
|
|
|
<< MakeSmartPtrFunctionName;
|
2016-10-31 23:48:01 +08:00
|
|
|
|
2017-08-04 19:18:00 +08:00
|
|
|
// Disable the fix in macros.
|
|
|
|
if (InMacro) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:14:52 +08:00
|
|
|
if (!replaceNew(Diag, New, SM)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-31 23:48:01 +08:00
|
|
|
Diag << FixItHint::CreateReplacement(
|
|
|
|
CharSourceRange::getCharRange(OperatorLoc, ExprEnd),
|
2017-07-05 15:49:00 +08:00
|
|
|
(llvm::Twine(" = ") + MakeSmartPtrFunctionName + "<" +
|
2017-06-27 16:31:27 +08:00
|
|
|
GetNewExprName(New, SM, getLangOpts()) + ">")
|
2016-10-31 23:48:01 +08:00
|
|
|
.str());
|
|
|
|
|
|
|
|
if (Expr->isArrow())
|
|
|
|
Diag << FixItHint::CreateInsertion(ExprStart, "*");
|
|
|
|
|
2017-07-05 15:49:00 +08:00
|
|
|
insertHeader(Diag, SM.getFileID(OperatorLoc));
|
2016-10-31 23:48:01 +08:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:14:52 +08:00
|
|
|
bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
|
2017-06-28 00:25:05 +08:00
|
|
|
const CXXNewExpr *New,
|
|
|
|
SourceManager& SM) {
|
2016-05-03 00:56:39 +08:00
|
|
|
SourceLocation NewStart = New->getSourceRange().getBegin();
|
|
|
|
SourceLocation NewEnd = New->getSourceRange().getEnd();
|
2017-06-28 00:25:05 +08:00
|
|
|
|
2018-01-23 19:43:18 +08:00
|
|
|
// Skip when the source location of the new expression is invalid.
|
|
|
|
if (NewStart.isInvalid() || NewEnd.isInvalid())
|
|
|
|
return false;
|
|
|
|
|
2017-06-28 00:25:05 +08:00
|
|
|
std::string ArraySizeExpr;
|
|
|
|
if (const auto* ArraySize = New->getArraySize()) {
|
|
|
|
ArraySizeExpr = Lexer::getSourceText(CharSourceRange::getTokenRange(
|
|
|
|
ArraySize->getSourceRange()),
|
|
|
|
SM, getLangOpts())
|
|
|
|
.str();
|
|
|
|
}
|
|
|
|
|
2016-05-03 00:56:39 +08:00
|
|
|
switch (New->getInitializationStyle()) {
|
|
|
|
case CXXNewExpr::NoInit: {
|
2017-06-28 00:25:05 +08:00
|
|
|
if (ArraySizeExpr.empty()) {
|
|
|
|
Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
|
|
|
|
} else {
|
|
|
|
// New array expression without written initializer:
|
|
|
|
// smart_ptr<Foo[]>(new Foo[5]);
|
|
|
|
Diag << FixItHint::CreateReplacement(SourceRange(NewStart, NewEnd),
|
|
|
|
ArraySizeExpr);
|
|
|
|
}
|
2016-05-03 00:56:39 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CXXNewExpr::CallInit: {
|
2017-08-24 21:35:55 +08:00
|
|
|
// FIXME: Add fixes for constructors with parameters that can be created
|
|
|
|
// with a C++11 braced-init-list (e.g. std::vector, std::map).
|
2017-08-17 18:14:52 +08:00
|
|
|
// Unlike ordinal cases, braced list can not be deduced in
|
|
|
|
// std::make_smart_ptr, we need to specify the type explicitly in the fixes:
|
|
|
|
// struct S { S(std::initializer_list<int>, int); };
|
2017-08-24 21:35:55 +08:00
|
|
|
// struct S2 { S2(std::vector<int>); };
|
2017-08-17 18:14:52 +08:00
|
|
|
// smart_ptr<S>(new S({1, 2, 3}, 1)); // C++98 call-style initialization
|
|
|
|
// smart_ptr<S>(new S({}, 1));
|
2017-08-24 21:35:55 +08:00
|
|
|
// smart_ptr<S2>(new S2({1})); // implicit conversion:
|
|
|
|
// // std::initializer_list => std::vector
|
2017-08-17 18:14:52 +08:00
|
|
|
// The above samples have to be replaced with:
|
|
|
|
// std::make_smart_ptr<S>(std::initializer_list<int>({1, 2, 3}), 1);
|
|
|
|
// std::make_smart_ptr<S>(std::initializer_list<int>({}), 1);
|
2017-08-24 21:35:55 +08:00
|
|
|
// std::make_smart_ptr<S2>(std::vector<int>({1}));
|
2017-08-17 18:14:52 +08:00
|
|
|
if (const auto *CE = New->getConstructExpr()) {
|
|
|
|
for (const auto *Arg : CE->arguments()) {
|
2017-08-24 21:35:55 +08:00
|
|
|
if (isa<CXXStdInitializerListExpr>(Arg)) {
|
2017-08-17 18:14:52 +08:00
|
|
|
return false;
|
|
|
|
}
|
2018-01-18 16:58:18 +08:00
|
|
|
// Check whether we construct a class from a std::initializer_list.
|
|
|
|
// If so, we won't generate the fixes.
|
|
|
|
auto IsStdInitListInitConstructExpr = [](const Expr* E) {
|
|
|
|
assert(E);
|
|
|
|
if (const auto *ImplicitCE = dyn_cast<CXXConstructExpr>(E)) {
|
|
|
|
if (ImplicitCE->isStdInitListInitialization())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2018-03-06 22:34:35 +08:00
|
|
|
if (IsStdInitListInitConstructExpr(Arg->IgnoreImplicit()))
|
2018-01-18 16:58:18 +08:00
|
|
|
return false;
|
2017-08-17 18:14:52 +08:00
|
|
|
}
|
|
|
|
}
|
2017-06-28 00:25:05 +08:00
|
|
|
if (ArraySizeExpr.empty()) {
|
|
|
|
SourceRange InitRange = New->getDirectInitRange();
|
|
|
|
Diag << FixItHint::CreateRemoval(
|
|
|
|
SourceRange(NewStart, InitRange.getBegin()));
|
|
|
|
Diag << FixItHint::CreateRemoval(SourceRange(InitRange.getEnd(), NewEnd));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// New array expression with default/value initialization:
|
|
|
|
// smart_ptr<Foo[]>(new int[5]());
|
|
|
|
// smart_ptr<Foo[]>(new Foo[5]());
|
|
|
|
Diag << FixItHint::CreateReplacement(SourceRange(NewStart, NewEnd),
|
|
|
|
ArraySizeExpr);
|
|
|
|
}
|
2016-05-03 00:56:39 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CXXNewExpr::ListInit: {
|
|
|
|
// Range of the substring that we do not want to remove.
|
|
|
|
SourceRange InitRange;
|
|
|
|
if (const auto *NewConstruct = New->getConstructExpr()) {
|
2017-08-04 16:07:05 +08:00
|
|
|
if (NewConstruct->isStdInitListInitialization()) {
|
2017-08-17 18:14:52 +08:00
|
|
|
// FIXME: Add fixes for direct initialization with the initializer-list
|
|
|
|
// constructor. Similar to the above CallInit case, the type has to be
|
|
|
|
// specified explicitly in the fixes.
|
|
|
|
// struct S { S(std::initializer_list<int>); };
|
|
|
|
// smart_ptr<S>(new S{1, 2, 3}); // C++11 direct list-initialization
|
|
|
|
// smart_ptr<S>(new S{}); // use initializer-list consturctor
|
|
|
|
// The above cases have to be replaced with:
|
|
|
|
// std::make_smart_ptr<S>(std::initializer_list<int>({1, 2, 3}));
|
|
|
|
// std::make_smart_ptr<S>(std::initializer_list<int>({}));
|
|
|
|
return false;
|
2017-08-04 16:07:05 +08:00
|
|
|
} else {
|
|
|
|
// Direct initialization with ordinary constructors.
|
|
|
|
// struct S { S(int x); S(); };
|
|
|
|
// smart_ptr<S>(new S{5});
|
|
|
|
// smart_ptr<S>(new S{}); // use default constructor
|
|
|
|
// The arguments in the initialization list are going to be forwarded to
|
|
|
|
// the constructor, so this has to be replaced with:
|
|
|
|
// std::make_smart_ptr<S>(5);
|
|
|
|
// std::make_smart_ptr<S>();
|
|
|
|
InitRange = SourceRange(
|
|
|
|
NewConstruct->getParenOrBraceRange().getBegin().getLocWithOffset(1),
|
|
|
|
NewConstruct->getParenOrBraceRange().getEnd().getLocWithOffset(-1));
|
|
|
|
}
|
2016-05-03 00:56:39 +08:00
|
|
|
} else {
|
|
|
|
// Aggregate initialization.
|
|
|
|
// smart_ptr<Pair>(new Pair{first, second});
|
|
|
|
// Has to be replaced with:
|
|
|
|
// smart_ptr<Pair>(Pair{first, second});
|
|
|
|
InitRange = SourceRange(
|
|
|
|
New->getAllocatedTypeSourceInfo()->getTypeLoc().getLocStart(),
|
|
|
|
New->getInitializer()->getSourceRange().getEnd());
|
|
|
|
}
|
|
|
|
Diag << FixItHint::CreateRemoval(
|
|
|
|
CharSourceRange::getCharRange(NewStart, InitRange.getBegin()));
|
|
|
|
Diag << FixItHint::CreateRemoval(
|
|
|
|
SourceRange(InitRange.getEnd().getLocWithOffset(1), NewEnd));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-08-17 18:14:52 +08:00
|
|
|
return true;
|
2016-05-03 00:56:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-05 15:49:00 +08:00
|
|
|
void MakeSmartPtrCheck::insertHeader(DiagnosticBuilder &Diag, FileID FD) {
|
|
|
|
if (MakeSmartPtrFunctionHeader.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auto IncludeFixit = Inserter->CreateIncludeInsertion(
|
|
|
|
FD, MakeSmartPtrFunctionHeader,
|
|
|
|
/*IsAngled=*/MakeSmartPtrFunctionHeader == StdMemoryHeader)) {
|
|
|
|
Diag << *IncludeFixit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 00:56:39 +08:00
|
|
|
} // namespace modernize
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|