36AST_MATCHER(Expr, isLValue) {
return Node.getValueKind() == VK_LValue; }
52 const auto AutoPtrDecl = recordDecl(hasName(
"auto_ptr"), isInStdNamespace());
53 const auto AutoPtrType =
54 hasCanonicalType(recordType(hasDeclaration(AutoPtrDecl)));
64 Finder->addMatcher(typeLoc(loc(qualType(AutoPtrType))).bind(
AutoPtrTokenId),
69 Finder->addMatcher(usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(namedDecl(
70 hasName(
"auto_ptr"), isInStdNamespace()))))
80 const auto MovableArgumentMatcher =
84 cxxOperatorCallExpr(hasOverloadedOperatorName(
"="),
85 callee(cxxMethodDecl(ofClass(AutoPtrDecl))),
86 hasArgument(1, MovableArgumentMatcher)),
90 cxxConstructExpr(hasType(AutoPtrType), argumentCountIs(1),
91 hasArgument(0, MovableArgumentMatcher))),
102 const SourceManager &SM = *Result.SourceManager;
105 const CharSourceRange Range = Lexer::makeFileCharRange(
106 CharSourceRange::getTokenRange(E->getSourceRange()), SM, LangOptions());
108 if (Range.isInvalid())
112 diag(Range.getBegin(),
"use std::move to transfer ownership")
113 << FixItHint::CreateInsertion(Range.getBegin(),
"std::move(")
114 << FixItHint::CreateInsertion(Range.getEnd(),
")")
115 << Inserter.createMainFileIncludeInsertion(
"<utility>");
120 SourceLocation AutoPtrLoc;
121 if (
const auto *PTL = Result.Nodes.getNodeAs<TypeLoc>(
AutoPtrTokenId)) {
123 if (
const auto QTL = TL.getAs<QualifiedTypeLoc>())
124 TL = QTL.getUnqualifiedLoc();
127 if (
const auto Loc = TL.getAs<TemplateSpecializationTypeLoc>())
128 AutoPtrLoc = Loc.getTemplateNameLoc();
129 }
else if (
const auto *D =
133 AutoPtrLoc = D->getNameInfo().getBeginLoc();
135 llvm_unreachable(
"Bad Callback. No node provided.");
138 if (AutoPtrLoc.isMacroID())
139 AutoPtrLoc = SM.getSpellingLoc(AutoPtrLoc);
143 if (StringRef(SM.getCharacterData(AutoPtrLoc), strlen(
"auto_ptr")) !=
147 const SourceLocation EndLoc =
148 AutoPtrLoc.getLocWithOffset(strlen(
"auto_ptr") - 1);
149 diag(AutoPtrLoc,
"auto_ptr is deprecated, use unique_ptr instead")
150 << FixItHint::CreateReplacement(SourceRange(AutoPtrLoc, EndLoc),
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.