rsmith added a comment. In D63960#1712398 <https://reviews.llvm.org/D63960#1712398>, @Tyker wrote:
> The now that constexpr destructors are legal. The code in this patch need to > be adapted, I have question about the following code. > > struct A { > constexpr ~A() {} > }; > > consteval A f() { > return A{}; > } > > void test() { > A a; > a = f(); // <-- here > } > > > At the point i marked. > The invocation of f causes an immediate invocation > (http://eel.is/c++draft/expr.const#12). > Immediate invocation are full expression > (http://eel.is/c++draft/intro.execution#5). > Full expression resolve all there side-effects before evaluating the next > full expression (http://eel.is/c++draft/intro.execution#9). > The return value of f() is created inside the immediate invocation. > So the destructor of the value returned by f() should be destroyed within > the immediate evaluation. > But that value is needed for the assignment operator. > This seem contradictory. What have i misunderstood ? What should happen here > ? After desugaring, the above example looks like this: a.operator=( <temporary materialization conversion>( <consteval full-expression>( f() ) ) ); That is: the temporary is materialized outside the immediate evaluation, so no `A` destructor should be run as part of evaluating that full-expression (the destructor is run in the enclosing full-expression). If the example were instead: constexpr A g() { return A {}; } consteval A &id (A &&a) { return a; } void test() { A a; a = id(g()); } then we would have a.operator=( <consteval full-expression>( id( <temporary materialization conversion>( g() ) ) ) ); ... and now the `A` temporary should be destroyed inside the full-expression. This example is ill-formed because the `id` call is not a constant expression (because its evaluated value refers to an object with automatic storage duration). CHANGES SINCE LAST ACTION https://reviews.llvm.org/D63960/new/ https://reviews.llvm.org/D63960 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits