50 auto AutoPtrDecl = recordDecl(hasName(
"auto_ptr"), isInStdNamespace());
51 auto AutoPtrType = hasCanonicalType(recordType(hasDeclaration(AutoPtrDecl)));
61 Finder->addMatcher(typeLoc(loc(qualType(AutoPtrType))).bind(AutoPtrTokenId),
66 Finder->addMatcher(usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(namedDecl(
67 hasName(
"auto_ptr"), isInStdNamespace()))))
68 .bind(AutoPtrTokenId),
77 auto MovableArgumentMatcher =
78 expr(isLValue(), hasType(AutoPtrType)).bind(AutoPtrOwnershipTransferId);
81 cxxOperatorCallExpr(hasOverloadedOperatorName(
"="),
82 callee(cxxMethodDecl(ofClass(AutoPtrDecl))),
83 hasArgument(1, MovableArgumentMatcher)),
87 cxxConstructExpr(hasType(AutoPtrType), argumentCountIs(1),
88 hasArgument(0, MovableArgumentMatcher))),
99 SourceManager &SM = *Result.SourceManager;
101 Result.Nodes.getNodeAs<Expr>(AutoPtrOwnershipTransferId)) {
102 CharSourceRange Range = Lexer::makeFileCharRange(
103 CharSourceRange::getTokenRange(E->getSourceRange()), SM, LangOptions());
105 if (Range.isInvalid())
108 auto Diag = diag(Range.getBegin(),
"use std::move to transfer ownership")
109 << FixItHint::CreateInsertion(Range.getBegin(),
"std::move(")
110 << FixItHint::CreateInsertion(Range.getEnd(),
")")
111 << Inserter.createMainFileIncludeInsertion(
"<utility>");
116 SourceLocation AutoPtrLoc;
117 if (
const auto *PTL = Result.Nodes.getNodeAs<TypeLoc>(AutoPtrTokenId)) {
119 if (
auto QTL = TL.getAs<QualifiedTypeLoc>())
120 TL = QTL.getUnqualifiedLoc();
123 if (
auto Loc = TL.getAs<TemplateSpecializationTypeLoc>())
124 AutoPtrLoc = Loc.getTemplateNameLoc();
125 }
else if (
const auto *D =
126 Result.Nodes.getNodeAs<UsingDecl>(AutoPtrTokenId)) {
129 AutoPtrLoc = D->getNameInfo().getBeginLoc();
131 llvm_unreachable(
"Bad Callback. No node provided.");
134 if (AutoPtrLoc.isMacroID())
135 AutoPtrLoc = SM.getSpellingLoc(AutoPtrLoc);
139 if (StringRef(SM.getCharacterData(AutoPtrLoc), strlen(
"auto_ptr")) !=
143 SourceLocation EndLoc = AutoPtrLoc.getLocWithOffset(strlen(
"auto_ptr") - 1);
144 diag(AutoPtrLoc,
"auto_ptr is deprecated, use unique_ptr instead")
145 << FixItHint::CreateReplacement(SourceRange(AutoPtrLoc, EndLoc),
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.