Skip to content

[Clang] Fix finding instantiated decls for class template specializations during instantiation #72346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 21, 2023
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/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ Bug Fixes in This Version

- Fixed an issue that a benign assertion might hit when instantiating a pack expansion
inside a lambda. (`#61460 <https://github.com/llvm/llvm-project/issues/61460>`_)
- Fix crash during instantiation of some class template specializations within class
templates. Fixes (`#70375 <https://github.com/llvm/llvm-project/issues/70375>`_)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6207,13 +6207,13 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
return D;

// Determine whether this record is the "templated" declaration describing
// a class template or class template partial specialization.
// a class template or class template specialization.
ClassTemplateDecl *ClassTemplate = Record->getDescribedClassTemplate();
if (ClassTemplate)
ClassTemplate = ClassTemplate->getCanonicalDecl();
else if (ClassTemplatePartialSpecializationDecl *PartialSpec
= dyn_cast<ClassTemplatePartialSpecializationDecl>(Record))
ClassTemplate = PartialSpec->getSpecializedTemplate()->getCanonicalDecl();
else if (ClassTemplateSpecializationDecl *Spec =
dyn_cast<ClassTemplateSpecializationDecl>(Record))
ClassTemplate = Spec->getSpecializedTemplate()->getCanonicalDecl();

// Walk the current context to find either the record or an instantiation of
// it.
Expand Down
33 changes: 33 additions & 0 deletions clang/test/SemaCXX/template-specialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,36 @@ int main() {
B::foo<4>(); // expected-note {{in instantiation of function template specialization 'B::foo<4>'}}
return 0;
}

namespace GH70375 {

template <typename Ty>
struct S {
static void bar() {
Ty t;
t.foo();
}

static void take(Ty&) {}
};

template <typename P>
struct Outer {
template <typename C>
struct Inner;

using U = S<Inner<P>>;

template <>
struct Inner<void> {
void foo() {
U::take(*this);
}
};
};

void instantiate() {
Outer<void>::U::bar();
}

}