Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ class RenamerClangTidyVisitor
const TemplateDecl *Decl =
Loc.getTypePtr()->getTemplateName().getAsTemplateDecl(
/*IgnoreDeduced=*/true);
if (!Decl)
return true;

if (const auto *ClassDecl = dyn_cast<TemplateDecl>(Decl))
if (const NamedDecl *TemplDecl = ClassDecl->getTemplatedDecl())
Expand Down
28 changes: 6 additions & 22 deletions clang-tools-extra/clangd/FindTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,6 @@ struct TargetFinder {
}
}
}
void VisitDependentTemplateSpecializationType(
const DependentTemplateSpecializationType *DTST) {
if (Outer.Resolver) {
for (const NamedDecl *ND :
Outer.Resolver->resolveTemplateSpecializationType(DTST)) {
Outer.add(ND, Flags);
}
}
}
void VisitTypedefType(const TypedefType *TT) {
if (shouldSkipTypedef(TT->getDecl()))
return;
Expand Down Expand Up @@ -455,11 +446,13 @@ struct TargetFinder {
// class template specializations have a (specialized) CXXRecordDecl.
else if (const CXXRecordDecl *RD = TST->getAsCXXRecordDecl())
Outer.add(RD, Flags); // add(Decl) will despecialize if needed.
else {
else if (auto *TD = TST->getTemplateName().getAsTemplateDecl())
// fallback: the (un-specialized) declaration from primary template.
if (auto *TD = TST->getTemplateName().getAsTemplateDecl())
Outer.add(TD->getTemplatedDecl(), Flags | Rel::TemplatePattern);
}
Outer.add(TD->getTemplatedDecl(), Flags | Rel::TemplatePattern);
else if (Outer.Resolver)
for (const NamedDecl *ND :
Outer.Resolver->resolveTemplateSpecializationType(TST))
Outer.add(ND, Flags);
}
void
VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *STTPT) {
Expand Down Expand Up @@ -900,15 +893,6 @@ refInTypeLoc(TypeLoc L, const HeuristicResolver *Resolver) {
DeclRelation::Alias, Resolver)});
}

void VisitDependentTemplateSpecializationTypeLoc(
DependentTemplateSpecializationTypeLoc L) {
Refs.push_back(
ReferenceLoc{L.getQualifierLoc(), L.getTemplateNameLoc(),
/*IsDecl=*/false,
explicitReferenceTargets(
DynTypedNode::create(L.getType()), {}, Resolver)});
}

void VisitDependentNameTypeLoc(DependentNameTypeLoc L) {
Refs.push_back(
ReferenceLoc{L.getQualifierLoc(), L.getNameLoc(),
Expand Down
16 changes: 6 additions & 10 deletions clang-tools-extra/clangd/SemanticHighlighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,11 +728,6 @@ class CollectExtraHighlightings
return true;
}

bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc L) {
H.addAngleBracketTokens(L.getLAngleLoc(), L.getRAngleLoc());
return true;
}

bool VisitFunctionDecl(FunctionDecl *D) {
if (D->isOverloadedOperator()) {
const auto AddOpDeclToken = [&](SourceLocation Loc) {
Expand Down Expand Up @@ -1087,11 +1082,12 @@ class CollectExtraHighlightings
return true;
}

bool VisitDependentTemplateSpecializationTypeLoc(
DependentTemplateSpecializationTypeLoc L) {
H.addToken(L.getTemplateNameLoc(), HighlightingKind::Type)
.addModifier(HighlightingModifier::DependentName)
.addModifier(HighlightingModifier::ClassScope);
bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc L) {
if (!L.getTypePtr()->getTemplateName().getAsTemplateDecl(
/*IgnoreDeduced=*/true))
H.addToken(L.getTemplateNameLoc(), HighlightingKind::Type)
.addModifier(HighlightingModifier::DependentName)
.addModifier(HighlightingModifier::ClassScope);
H.addAngleBracketTokens(L.getLAngleLoc(), L.getRAngleLoc());
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions clang-tools-extra/clangd/unittests/FindTargetTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,7 @@ TEST_F(TargetDeclTest, DependentTypes) {
template <typename T>
void foo(typename A<T>::template [[B]]<int>);
)cpp";
EXPECT_DECLS("DependentTemplateSpecializationTypeLoc",
"template <typename> struct B");
EXPECT_DECLS("TemplateSpecializationTypeLoc", "template <typename> struct B");

// Dependent name with recursive definition. We don't expect a
// result, but we shouldn't get into a stack overflow either.
Expand Down
2 changes: 2 additions & 0 deletions clang-tools-extra/include-cleaner/lib/WalkAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {

// TypeLoc visitors.
void reportType(SourceLocation RefLoc, NamedDecl *ND) {
if (!ND)
return;
// Reporting explicit references to types nested inside classes can cause
// issues, e.g. a type accessed through a derived class shouldn't require
// inclusion of the base.
Expand Down
4 changes: 3 additions & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ AST Matchers
following the corresponding changes in the clang AST.
- Ensure ``hasBitWidth`` doesn't crash on bit widths that are dependent on template
parameters.

- Remove the ``dependentTemplateSpecializationType`` matcher, as the
corresponding AST node was removed. This matcher was never very useful, since
there was no way to match on its template name.
- Add a boolean member ``IgnoreSystemHeaders`` to ``MatchFinderOptions``. This
allows it to ignore nodes in system headers when traversing the AST.

Expand Down
13 changes: 2 additions & 11 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
mutable llvm::FoldingSet<UsingType> UsingTypes;
mutable llvm::FoldingSet<FoldingSetPlaceholder<TypedefType>> TypedefTypes;
mutable llvm::FoldingSet<DependentNameType> DependentNameTypes;
mutable llvm::DenseMap<llvm::FoldingSetNodeID,
DependentTemplateSpecializationType *>
DependentTemplateSpecializationTypes;
mutable llvm::FoldingSet<PackExpansionType> PackExpansionTypes;
mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes;
mutable llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
Expand Down Expand Up @@ -1904,7 +1901,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
TemplateTypeParmDecl *ParmDecl = nullptr) const;

QualType getCanonicalTemplateSpecializationType(
TemplateName T, ArrayRef<TemplateArgument> CanonicalArgs) const;
ElaboratedTypeKeyword Keyword, TemplateName T,
ArrayRef<TemplateArgument> CanonicalArgs) const;

QualType
getTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName T,
Expand Down Expand Up @@ -1935,13 +1933,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
NestedNameSpecifier NNS,
const IdentifierInfo *Name) const;

QualType getDependentTemplateSpecializationType(
ElaboratedTypeKeyword Keyword, const DependentTemplateStorage &Name,
ArrayRef<TemplateArgumentLoc> Args) const;
QualType getDependentTemplateSpecializationType(
ElaboratedTypeKeyword Keyword, const DependentTemplateStorage &Name,
ArrayRef<TemplateArgument> Args, bool IsCanonical = false) const;

TemplateArgument getInjectedTemplateArg(NamedDecl *ParamDecl) const;

/// Form a pack expansion type with the given pattern.
Expand Down
5 changes: 0 additions & 5 deletions clang/include/clang/AST/ASTNodeTraverser.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,6 @@ class ASTNodeTraverser
for (unsigned I=0, N=TL.getNumArgs(); I < N; ++I)
dumpTemplateArgumentLoc(TL.getArgLoc(I));
}
void VisitDependentTemplateSpecializationTypeLoc(
DependentTemplateSpecializationTypeLoc TL) {
for (unsigned I=0, N=TL.getNumArgs(); I < N; ++I)
dumpTemplateArgumentLoc(TL.getArgLoc(I));
}

void VisitTypedefDecl(const TypedefDecl *D) { Visit(D->getUnderlyingType()); }

Expand Down
16 changes: 0 additions & 16 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1192,13 +1192,6 @@ DEF_TRAVERSE_TYPE(DependentNameType, {
TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
})

DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
const DependentTemplateStorage &S = T->getDependentTemplateName();
if (TraverseQualifier)
TRY_TO(TraverseNestedNameSpecifier(S.getQualifier()));
TRY_TO(TraverseTemplateArguments(T->template_arguments()));
})

DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
if (TraverseQualifier) {
TRY_TO(TraverseTemplateName(T->getTemplateName()));
Expand Down Expand Up @@ -1546,15 +1539,6 @@ DEF_TRAVERSE_TYPELOC(DependentNameType, {
TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
})

DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
if (TraverseQualifier)
TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));

for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
}
})

DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
if (TraverseQualifier)
TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/TemplateName.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ class TemplateName {
/// set of function templates, returns NULL.
TemplateDecl *getAsTemplateDecl(bool IgnoreDeduced = false) const;

/// Retrieves the underlying template declaration that
/// Retrieves the underlying template name that
/// this template name refers to, along with the
/// deduced default arguments, if any.
std::pair<TemplateDecl *, DefaultArguments>
std::pair<TemplateName, DefaultArguments>
getTemplateDeclAndDefaultArgs() const;

/// Retrieve the underlying, overloaded function template
Expand Down
64 changes: 3 additions & 61 deletions clang/include/clang/AST/TypeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -2250,22 +2250,6 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
unsigned NumArgs;
};

class DependentTemplateSpecializationTypeBitfields {
friend class DependentTemplateSpecializationType;

LLVM_PREFERRED_TYPE(KeywordWrapperBitfields)
unsigned : NumTypeWithKeywordBits;

/// The number of template arguments named in this class template
/// specialization, which is expected to be able to hold at least 1024
/// according to [implimits]. However, as this limit is somewhat easy to
/// hit with template metaprogramming we'd prefer to keep it as large
/// as possible. At the moment it has been left as a non-bitfield since
/// this type safely fits in 64 bits as an unsigned, so there is no reason
/// to introduce the performance impact of a bitfield.
unsigned NumArgs;
};

class PackExpansionTypeBitfields {
friend class PackExpansionType;

Expand Down Expand Up @@ -2346,8 +2330,6 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
SubstTemplateTypeParmTypeBitfields SubstTemplateTypeParmTypeBits;
SubstPackTypeBitfields SubstPackTypeBits;
TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits;
DependentTemplateSpecializationTypeBitfields
DependentTemplateSpecializationTypeBits;
PackExpansionTypeBitfields PackExpansionTypeBits;
CountAttributedTypeBitfields CountAttributedTypeBits;
PresefinedSugarTypeBitfields PredefinedSugarTypeBits;
Expand Down Expand Up @@ -7366,9 +7348,9 @@ class TemplateSpecializationType : public TypeWithKeyword,
}

void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
ArrayRef<TemplateArgument> Args, QualType Underlying,
const ASTContext &Context);
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
TemplateName T, ArrayRef<TemplateArgument> Args,
QualType Underlying, const ASTContext &Context);

static bool classof(const Type *T) {
return T->getTypeClass() == TemplateSpecialization;
Expand Down Expand Up @@ -7459,46 +7441,6 @@ class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
}
};

/// Represents a template specialization type whose template cannot be
/// resolved, e.g.
/// A<T>::template B<T>
class DependentTemplateSpecializationType : public TypeWithKeyword {
friend class ASTContext; // ASTContext creates these

DependentTemplateStorage Name;

DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
const DependentTemplateStorage &Name,
ArrayRef<TemplateArgument> Args,
QualType Canon);

public:
const DependentTemplateStorage &getDependentTemplateName() const {
return Name;
}

ArrayRef<TemplateArgument> template_arguments() const {
return {reinterpret_cast<const TemplateArgument *>(this + 1),
DependentTemplateSpecializationTypeBits.NumArgs};
}

bool isSugared() const { return false; }
QualType desugar() const { return QualType(this, 0); }

void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
Profile(ID, Context, getKeyword(), Name, template_arguments());
}

static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
ElaboratedTypeKeyword Keyword,
const DependentTemplateStorage &Name,
ArrayRef<TemplateArgument> Args);

static bool classof(const Type *T) {
return T->getTypeClass() == DependentTemplateSpecialization;
}
};

/// Represents a pack expansion of types.
///
/// Pack expansions are part of C++11 variadic templates. A pack
Expand Down
Loading