[clang] [C++20][Coroutines] Lambda-coroutine with operator new in promise_type (PR #84193)
Andreas Fertig via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 6 22:55:35 PST 2024
================
@@ -6898,10 +6898,18 @@ class Sema final {
BinaryOperatorKind Operator);
//// ActOnCXXThis - Parse 'this' pointer.
- ExprResult ActOnCXXThis(SourceLocation loc);
+ ///
+ /// \param SkipLambdaCaptureCheck Whether to skip the 'this' check for a
+ /// lambda because 'this' is the lambda's 'this'-pointer.
+ ExprResult ActOnCXXThis(SourceLocation loc,
+ bool SkipLambdaCaptureCheck = false);
----------------
andreasfertig wrote:
Sure, have a look at this code (https://cppinsights.io/s/3212c7be)
```
class Test {
int a;
public:
Test(int x)
: a{x}
{
int other{};
auto l1 = [=] { return a + 2 + other; };
}
};
```
The lambda `l1` has _two_ things that we refer to as `this`-pointer. It's very own, as every non-static member function has. Used to access `other` like `this->other` inside the lambdas body. That `this`-pointer isn't captured. Hence, no check.
Then the captured `this`-pointer from the enclosing scope of `Test`. In C++ Insights called `__this`. While being used it looks like `this->__this->a`.
The check is in place for the latter. For the use case of calling `operator new` in the case of a coroutine, we are talking about the first one, which isn't captured.
While writing about this, I haven't checked whether a `promise_type` with a constructor worked before or does so now. I can check that maybe tomorrow.
https://github.com/llvm/llvm-project/pull/84193
More information about the cfe-commits
mailing list