Skip to content

[clang] Fixed an assertion failure triggered when instantiating a template with an expr that references an invalid decl #140905

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -579,6 +579,8 @@ Bug Fixes in This Version
``#include`` directive. (#GH138094)
- Fixed a crash during constant evaluation involving invalid lambda captures
(#GH138832)
- Fixed an assertion failure triggered when instantiating a template with an
expression that references an invalid declaration (#GH140898)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4552,6 +4552,9 @@ LocalInstantiationScope::findInstantiationOf(const Decl *D) {
isa<CXXDeductionGuideDecl>(D->getDeclContext()))
return nullptr;

if (D->isInvalidDecl())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we just check after D = getCanonicalParmVarDecl(D);?

return nullptr;

// If we didn't find the decl, then we either have a sema bug, or we have a
// forward reference to a label declaration. Return null to indicate that
// we have an uninstantiated label.
Expand Down
10 changes: 10 additions & 0 deletions clang/test/SemaCXX/gh140898.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
template <typename T>
void s() {
switch (Unknown tr = 1) // expected-error {{unknown type name 'Unknown'}}
tr;
}

void abc() {
s<int>();
}