36AST_MATCHER(Expr, isLValue) {
return Node.getValueKind() == VK_LValue; }
52 auto AutoPtrDecl = recordDecl(hasName(
"auto_ptr"), isInStdNamespace());
53 auto AutoPtrType = hasCanonicalType(recordType(hasDeclaration(AutoPtrDecl)));
63 Finder->addMatcher(typeLoc(loc(qualType(AutoPtrType))).bind(
AutoPtrTokenId),
68 Finder->addMatcher(usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(namedDecl(
69 hasName(
"auto_ptr"), isInStdNamespace()))))
79 auto MovableArgumentMatcher =
83 cxxOperatorCallExpr(hasOverloadedOperatorName(
"="),
84 callee(cxxMethodDecl(ofClass(AutoPtrDecl))),
85 hasArgument(1, MovableArgumentMatcher)),
89 cxxConstructExpr(hasType(AutoPtrType), argumentCountIs(1),
90 hasArgument(0, MovableArgumentMatcher))),
101 const SourceManager &SM = *Result.SourceManager;
104 const CharSourceRange Range = Lexer::makeFileCharRange(
105 CharSourceRange::getTokenRange(E->getSourceRange()), SM, LangOptions());
107 if (Range.isInvalid())
110 auto Diag = diag(Range.getBegin(),
"use std::move to transfer ownership")
111 << FixItHint::CreateInsertion(Range.getBegin(),
"std::move(")
112 << FixItHint::CreateInsertion(Range.getEnd(),
")")
113 << Inserter.createMainFileIncludeInsertion(
"<utility>");
118 SourceLocation AutoPtrLoc;
119 if (
const auto *PTL = Result.Nodes.getNodeAs<TypeLoc>(
AutoPtrTokenId)) {
121 if (
auto QTL = TL.getAs<QualifiedTypeLoc>())
122 TL = QTL.getUnqualifiedLoc();
125 if (
auto Loc = TL.getAs<TemplateSpecializationTypeLoc>())
126 AutoPtrLoc = Loc.getTemplateNameLoc();
127 }
else if (
const auto *D =
131 AutoPtrLoc = D->getNameInfo().getBeginLoc();
133 llvm_unreachable(
"Bad Callback. No node provided.");
136 if (AutoPtrLoc.isMacroID())
137 AutoPtrLoc = SM.getSpellingLoc(AutoPtrLoc);
141 if (StringRef(SM.getCharacterData(AutoPtrLoc), strlen(
"auto_ptr")) !=
145 const SourceLocation EndLoc =
146 AutoPtrLoc.getLocWithOffset(strlen(
"auto_ptr") - 1);
147 diag(AutoPtrLoc,
"auto_ptr is deprecated, use unique_ptr instead")
148 << FixItHint::CreateReplacement(SourceRange(AutoPtrLoc, EndLoc),
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.