Skip to content

Commit 741793c

Browse files
author
huqizhi
committed
[Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context
1 parent fa70b5d commit 741793c

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ Bug Fixes to C++ Support
204204
parameter where we did an incorrect specialization of the initialization of
205205
the default parameter.
206206
Fixes (`#68490 <https://github.com/llvm/llvm-project/issues/68490>`_)
207+
- Fix a crash in codegen when lambdas declared in an unevaluated context.
208+
Fixes (`#76674 <https://github.com/llvm/llvm-project/issues/76674>`_)
207209

208210
Bug Fixes to AST Handling
209211
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,8 +1613,8 @@ namespace {
16131613
bool TemplateInstantiator::AlreadyTransformed(QualType T) {
16141614
if (T.isNull())
16151615
return true;
1616-
1617-
if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
1616+
if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
1617+
(SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))
16181618
return false;
16191619

16201620
getSema().MarkDeclarationsReferencedInType(Loc, T);
@@ -2685,7 +2685,8 @@ QualType Sema::SubstType(QualType T,
26852685

26862686
// If T is not a dependent type or a variably-modified type, there
26872687
// is nothing to do.
2688-
if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
2688+
if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType() &&
2689+
(getLangOpts().CPlusPlus20 && !T->isDecltypeType()))
26892690
return T;
26902691

26912692
TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);

clang/test/CodeGen/PR76674.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -verify -std=c++20 -emit-llvm -o - %s
2+
// expected-no-diagnostics
3+
4+
template <class>
5+
struct A {
6+
template <class U>
7+
using Func = decltype([] {return U{};});
8+
};
9+
10+
A<int>::Func<int> f{};
11+
int i{f()};

0 commit comments

Comments
 (0)