Skip to content
Closed
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
3 changes: 3 additions & 0 deletions clang/lib/Index/IndexTypeSourceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TTPL) {
SourceLocation Loc = TTPL.getNameLoc();
TemplateTypeParmDecl *TTPD = TTPL.getDecl();
if (!TTPD)
return false;

return IndexCtx.handleReference(TTPD, Loc, Parent, ParentDC,
SymbolRoleSet());
}
Expand Down
16 changes: 16 additions & 0 deletions clang/test/Index/gh89389.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: c-index-test -test-load-source all %s -std=gnu++20 -fno-delayed-template-parsing

namespace test18 {
template<typename T>
concept False = false;

template <typename T> struct Foo { T t; };

template<typename T> requires False<T>
Foo(T) -> Foo<int>;

template <typename U>
using Bar = Foo<U>;

Bar s = {1};
} // namespace test18
8 changes: 6 additions & 2 deletions clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1693,12 +1693,16 @@ bool CursorVisitor::VisitTagTypeLoc(TagTypeLoc TL) {
}

bool CursorVisitor::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
if (const auto *TC = TL.getDecl()->getTypeConstraint()) {
TemplateTypeParmDecl *D = TL.getDecl();
if (!D)
return true;

if (const auto *TC = D->getTypeConstraint()) {
if (VisitTypeConstraint(*TC))
return true;
}

return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
return Visit(MakeCursorTypeRef(D, TL.getNameLoc(), TU));
}

bool CursorVisitor::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
Expand Down
27 changes: 27 additions & 0 deletions clang/unittests/Index/IndexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,33 @@ TEST(IndexTest, ReadWriteRoles) {
WrittenAt(Position(6, 17))))));
}

TEST(IndexTest, gh89389) {
std::string Code = R"cpp(
namespace test18 {
template<typename T>
concept False = false;

template <typename T> struct Foo { T t; };

template<typename T> requires False<T>
Foo(T) -> Foo<int>;

template <typename U>
using Bar = Foo<U>;

Bar s = {1};
} // namespace test18
)cpp";
auto Index = std::make_shared<Indexer>();
IndexingOptions Opts;
Opts.IndexTemplateParameters = true;

// This test case is invalid code, so the expected return value is `false`.
// What is being tested is that there is no crash.
EXPECT_FALSE(tooling::runToolOnCodeWithArgs(
std::make_unique<IndexAction>(Index, Opts), Code, {"-std=c++20"}));
}

} // namespace
} // namespace index
} // namespace clang