https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123989

            Bug ID: 123989
           Summary: Postfix-expression should be sequenced before each
                    expression in the expression-list
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: drippy_carnation182 at simplelogin dot com
  Target Milestone: ---

Please see
https://stackoverflow.com/questions/79882580/lambda-argument-that-steals-unique-ptr-used-to-do-the-call/79882716?noredirect=1#comment140971274_79882716

This program
```c++
#include <iostream>
#include <memory>
struct A {
  A() { std::cout << "A::A(), this: " << this << std::endl; }
  void call(auto lambda) const {
    std::cout << "A::call() this: " << this << std::endl;
    lambda();
  }
};

int main() {
  auto p{std::make_unique<A>()};
  p->call([p2 = std::move(p)] { std::cout << "From lambda" << std::endl; });
  return 0;
}
```
Prints out 

```
A::A(), this: 0x53aa2b0
A::call() this: 0x53aa2b0
>From lambda
```

while in this changed form using deducing this

```
#include <iostream>
#include <memory>
struct A {
  A() { std::cout << "A::A(), this: " << this << std::endl; }
  void call(this const auto& self, auto lambda) {
    std::cout << "A::call() this: " << &self << std::endl;
    lambda();
  }
};

int main() {
  auto p{std::make_unique<A>()};
  p->call([p2 = std::move(p)] { std::cout << "From lambda" << std::endl; });
  return 0;
}
```
it prints (see https://godbolt.org/z/qxjnf5KGq)

```
A::A(), this: 0x3fe662b0
A::call() this: 0
>From lambda
```

It should not print `A::call() this: 0` by
https://timsong-cpp.github.io/cppwp/n4659/expr.call#5
> The postfix-expression is sequenced before each expression in the 
> expression-list and any default argument.
  • [Bug c++/123989] N... drippy_carnation182 at simplelogin dot com via Gcc-bugs

Reply via email to