llvm-project/clang/test/SemaCXX/constexpr-explicit-object-lambda.cpp
Sirraide bd77a26e9a
[Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (#81102)
There were some bugs wrt explicit object parameters in lambdas in the
constant evaluator:
- The code evaluating a `CXXThisExpr` wasn’t checking for explicit
object parameters at all and thus assumed that there was no `this` in
the current context because the lambda didn’t have one, even though we
were in a member function and had captured its `this`.
- The code retrieving captures as lvalues *did* account for explicit
object parameters, but it did not handle the case of the explicit object
parameter being passed by value rather than by reference.

This fixes #80997.

---------

Co-authored-by: cor3ntin <corentinjabot@gmail.com>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2024-03-13 18:49:44 +01:00

35 lines
595 B
C++

// RUN: %clang_cc1 -std=c++23 -verify %s
// expected-no-diagnostics
struct S {
int i = 42;
constexpr auto f1() {
return [this](this auto) {
return this->i;
}();
};
constexpr auto f2() {
return [this](this auto&&) {
return this->i;
}();
};
constexpr auto f3() {
return [i = this->i](this auto) {
return i;
}();
};
constexpr auto f4() {
return [i = this->i](this auto&&) {
return i;
}();
};
};
static_assert(S().f1() == 42);
static_assert(S().f2() == 42);
static_assert(S().f3() == 42);
static_assert(S().f4() == 42);