Skip to content

Commit c64d4ce

Browse files
authored
[clang] fix lambda dependency issue with late parse attributes (#161765)
This fixes a regression introduced in #147835 When parsing a lambda where the call operator has a late parsed attribute, we would try to build a 'this' type for the lambda, but in a lambda 'this' never refers to the lambda class itself. This late parsed attribute can be added implicitly by the -ftrapping-math flag. This patch patch makes it so CXXThisScopeRAII ignores lambdas. This became observable in #147835 because that made clang lazily create tag types, and it removed a workaround for a lambda dependency bug where any previously created tag type for the lambda is discarded after its dependency is recalculated. But the 'this' scope created above would defeat this laziness and create the lambda type too soon, before its dependency was updated. Since this regression was never released, there are no release notes. Fixes #161657
1 parent d0e15f9 commit c64d4ce

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,10 @@ Sema::CXXThisScopeRAII::CXXThisScopeRAII(Sema &S,
12511251
else
12521252
Record = cast<CXXRecordDecl>(ContextDecl);
12531253

1254+
// 'this' never refers to the lambda class itself.
1255+
if (Record->isLambda())
1256+
return;
1257+
12541258
QualType T = S.Context.getCanonicalTagType(Record);
12551259
T = S.getASTContext().getQualifiedType(T, CXXThisTypeQuals);
12561260

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -fsyntax-only -std=c++20 -ffp-exception-behavior=strict -verify %s
2+
// expected-no-diagnostics
3+
4+
template <class T> struct S {
5+
template <class U> using type1 = decltype([] { return U{}; });
6+
};
7+
8+
void foo() {
9+
using T1 = S<int>::type1<int>;
10+
int x = T1()();
11+
}

0 commit comments

Comments
 (0)