Skip to content

Commit 82c83d7

Browse files
committed
[Clang] Fix evaluation of parameters of lambda call operator attributes
Fix a regresion introduced by D124351. Attributes of lambda call operator were evaluated in the context of the closure object type rather than its operator, causing an assertion failure. This was because we temporarily switch to the class lambda to produce the mangling of the lambda, but we stayed in that context too long. Reviewed By: eandrews, aaron.ballman Differential Revision: https://reviews.llvm.org/D146535
1 parent 5bcb4c4 commit 82c83d7

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

clang/lib/Sema/SemaLambda.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ buildTypeForLambdaCallOperator(Sema &S, clang::CXXRecordDecl *Class,
390390
void Sema::handleLambdaNumbering(
391391
CXXRecordDecl *Class, CXXMethodDecl *Method,
392392
std::optional<std::tuple<bool, unsigned, unsigned, Decl *>> Mangling) {
393+
394+
ContextRAII ManglingContext(*this, Class->getDeclContext());
395+
393396
if (Mangling) {
394397
bool HasKnownInternalLinkage;
395398
unsigned ManglingNumber, DeviceManglingNumber;
@@ -1324,8 +1327,6 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
13241327
ParamInfo.getDeclSpec().getConstexprSpecifier(),
13251328
IsLambdaStatic ? SC_Static : SC_None, Params, ExplicitResultType);
13261329

1327-
ContextRAII ManglingContext(*this, Class->getDeclContext());
1328-
13291330
CheckCXXDefaultArguments(Method);
13301331

13311332
// This represents the function body for the lambda function, check if we
@@ -1350,8 +1351,6 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
13501351

13511352
handleLambdaNumbering(Class, Method);
13521353

1353-
ManglingContext.pop();
1354-
13551354
for (auto &&C : LSI->Captures) {
13561355
if (!C.isVariableCapture())
13571356
continue;

clang/test/SemaCXX/lambda-expressions.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify -verify=expected-cxx14 -fblocks %s
2-
// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -fsyntax-only -verify -fblocks %s
2+
// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify -ast-dump -fblocks %s | FileCheck %s
33

44
namespace std { class type_info; };
55

@@ -704,3 +704,13 @@ static_assert([]() constexpr {
704704
}());
705705
} // namespace GH60936
706706
#endif
707+
708+
// Call operator attributes refering to a variable should
709+
// be properly handled after D124351
710+
constexpr int i = 2;
711+
void foo() {
712+
(void)[=][[gnu::aligned(i)]] () {}; // expected-warning{{C++2b extension}}
713+
// CHECK: AlignedAttr
714+
// CHECK-NEXT: ConstantExpr
715+
// CHECK-NEXT: value: Int 2
716+
}

0 commit comments

Comments
 (0)