Skip to content

[Sema] Fix assertion error in Sema::FindInstantiatedDecl #96509

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
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/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,9 @@ Bug Fixes in This Version

- ``typeof_unqual`` now properly removes type qualifiers from arrays and their element types. (#GH92667)

- Fixed an assertion failure when a template non-type parameter contains
an invalid expression.

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
7 changes: 6 additions & 1 deletion clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6229,7 +6229,12 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
getTrivialTemplateArgumentLoc(UnpackedArg, QualType(), Loc));
}
QualType T = CheckTemplateIdType(TemplateName(TD), Loc, Args);
if (T.isNull())
// We may get a non-null type with errors, in which case
// `getAsCXXRecordDecl` will return `nullptr`. For instance, this
// happens when one of the template arguments is an invalid
// expression. We return early to avoid triggering the assertion
// about the `CodeSynthesisContext`.
if (T.isNull() || T->containsErrors())
return nullptr;
CXXRecordDecl *SubstRecord = T->getAsCXXRecordDecl();

Expand Down
14 changes: 14 additions & 0 deletions clang/test/SemaCXX/instantiate-template-broken-nontype-default.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s

constexpr Missing a = 0; // expected-error {{unknown type name 'Missing'}}

template < typename T, Missing b = a> // expected-error {{unknown type name 'Missing'}}
class Klass { // expected-note {{candidate template ignored: could not match 'Klass<T, b>' against 'int'}} \
expected-note {{implicit deduction guide declared as 'template <typename T, int b = <recovery-expr>()> Klass(Klass<T, b>) -> Klass<T, b>'}}
Klass(T); // expected-note {{candidate template ignored: substitution failure [with T = int, b = <recovery-expr>()]}} \
expected-note {{implicit deduction guide declared as 'template <typename T, int b = <recovery-expr>()> Klass(T) -> Klass<T, b>'}}
};

Klass foo{5}; // no-crash \
expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'Klass'}}

Loading