Question Details

No question body available.

Tags

c++ language-lawyer order-of-execution

Answers (1)

Accepted Answer Available
Accepted Answer
February 4, 2026 Score: 6 Rep: 20,119 Quality: Expert Completeness: 80%

This is valid in C++17 and later, and UB before C++17.

In C++17 and later, the standard's [expr.call] says:

The postfix-expression is sequenced before each expression in the expression-list and any default argument.

A function call has the form:

postfix-expression ( expression-listopt )

So in the case of p->call([p2 = std::move(p)] { std::cout call is interpreted as (p.operator->())->call. So the result of operator-> is also computed before the evaluation of the lambda expression.

Before C++17, the evaluations of the postfix-expression and of the argument are unsequenced, so the two uses of p have undefined behavior.