// is already in there
RenamerClangTidyCheck::NamingCheckFailure &Failure =
NamingCheckFailures[Decl];
- if (!Failure.RawUsageLocs.insert(FixLocation.getRawEncoding()).second)
- return;
if (!Failure.ShouldFix())
return;
+ if (SourceMgr && SourceMgr->isWrittenInScratchSpace(FixLocation))
+ Failure.FixStatus = RenamerClangTidyCheck::ShouldFixStatus::InsideMacro;
+
if (!utils::rangeCanBeFixed(Range, SourceMgr))
Failure.FixStatus = RenamerClangTidyCheck::ShouldFixStatus::InsideMacro;
+
+ Failure.RawUsageLocs.insert(FixLocation.getRawEncoding());
}
void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range,
if (const auto *Decl =
Result.Nodes.getNodeAs<CXXConstructorDecl>("classRef")) {
- addUsage(Decl->getParent(), Decl->getNameInfo().getSourceRange());
+ addUsage(Decl->getParent(), Decl->getNameInfo().getSourceRange(),
+ Result.SourceManager);
for (const auto *Init : Decl->inits()) {
if (!Init->isWritten() || Init->isInClassMemberInitializer())
continue;
if (const FieldDecl *FD = Init->getAnyMember())
- addUsage(FD, SourceRange(Init->getMemberLocation()));
+ addUsage(FD, SourceRange(Init->getMemberLocation()),
+ Result.SourceManager);
// Note: delegating constructors and base class initializers are handled
// via the "typeLoc" matcher.
}
// we want instead to replace the next token, that will be the identifier.
Range.setBegin(CharSourceRange::getTokenRange(Range).getEnd());
- addUsage(Decl->getParent(), Range);
+ addUsage(Decl->getParent(), Range, Result.SourceManager);
return;
}
// further TypeLocs handled below
if (Decl) {
- addUsage(Decl, Loc->getSourceRange());
+ addUsage(Decl, Loc->getSourceRange(), Result.SourceManager);
return;
}
SourceRange Range(Ref.getTemplateNameLoc(), Ref.getTemplateNameLoc());
if (const auto *ClassDecl = dyn_cast<TemplateDecl>(Decl)) {
if (const NamedDecl *TemplDecl = ClassDecl->getTemplatedDecl())
- addUsage(TemplDecl, Range);
+ addUsage(TemplDecl, Range, Result.SourceManager);
return;
}
}
if (const auto &Ref =
Loc->getAs<DependentTemplateSpecializationTypeLoc>()) {
if (const TagDecl *Decl = Ref.getTypePtr()->getAsTagDecl())
- addUsage(Decl, Loc->getSourceRange());
+ addUsage(Decl, Loc->getSourceRange(), Result.SourceManager);
return;
}
}
Result.Nodes.getNodeAs<NestedNameSpecifierLoc>("nestedNameLoc")) {
if (const NestedNameSpecifier *Spec = Loc->getNestedNameSpecifier()) {
if (const NamespaceDecl *Decl = Spec->getAsNamespace()) {
- addUsage(Decl, Loc->getLocalSourceRange());
+ addUsage(Decl, Loc->getLocalSourceRange(), Result.SourceManager);
return;
}
}
if (const auto *Decl = Result.Nodes.getNodeAs<UsingDecl>("using")) {
for (const auto *Shadow : Decl->shadows())
- addUsage(Shadow->getTargetDecl(), Decl->getNameInfo().getSourceRange());
+ addUsage(Shadow->getTargetDecl(), Decl->getNameInfo().getSourceRange(),
+ Result.SourceManager);
return;
}
// Fix using namespace declarations.
if (const auto *UsingNS = dyn_cast<UsingDirectiveDecl>(Decl))
addUsage(UsingNS->getNominatedNamespaceAsWritten(),
- UsingNS->getIdentLocation());
+ UsingNS->getIdentLocation(), Result.SourceManager);
if (!Decl->getIdentifier() || Decl->getName().empty() || Decl->isImplicit())
return;
const auto *Canonical = cast<NamedDecl>(Decl->getCanonicalDecl());
if (Canonical != Decl) {
- addUsage(Canonical, Decl->getLocation());
+ addUsage(Canonical, Decl->getLocation(), Result.SourceManager);
return;
}
if (const auto *Value = Result.Nodes.getNodeAs<ValueDecl>("decl")) {
if (const Type *TypePtr = Value->getType().getTypePtrOrNull()) {
if (const auto *Typedef = TypePtr->getAs<TypedefType>())
- addUsage(Typedef->getDecl(), Value->getSourceRange());
+ addUsage(Typedef->getDecl(), Value->getSourceRange(),
+ Result.SourceManager);
}
}
if (const auto *Value = Result.Nodes.getNodeAs<FunctionDecl>("decl")) {
if (const auto *Typedef =
Value->getReturnType().getTypePtr()->getAs<TypedefType>())
- addUsage(Typedef->getDecl(), Value->getSourceRange());
+ addUsage(Typedef->getDecl(), Value->getSourceRange(),
+ Result.SourceManager);
for (const ParmVarDecl *Param : Value->parameters()) {
if (const TypedefType *Typedef =
Param->getType().getTypePtr()->getAs<TypedefType>())
- addUsage(Typedef->getDecl(), Value->getSourceRange());
+ addUsage(Typedef->getDecl(), Value->getSourceRange(),
+ Result.SourceManager);
}
}