The return of outer would be handled by return value optimization, effectively constructing outer in-place at a caller-defined location.

 

In this example it would be constructed in temporary stack space. The i refers to the inner i in f1, which is no longer in scope.

 

In practice, it would probably not crash, as inner has no member variables and do_something() does not dereference the this pointer.

The default constructor of outer is only called at the very end of the expression, so I do not understand, what difference it would make in regards to i.
 

-----Ursprüngliche Nachricht-----
Von: Jarrad Waterloo via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Fr 25.07.2025 15:33
Betreff: Re: [std-proposals] Standardising 0xdeadbeef for pointers
An: std-proposals@lists.isocpp.org;
CC: Jarrad Waterloo <descender76@gmail.com>;
I am more concerned about point of deletion than creation as in your example.
 
struct inner
{
    void do_something(){}
};
 
struct outer
{
    inner& i;
};
 
outer f1()
{
    inner i
    return outer{i};
}
 
f1().i. do_something();// crash hopefully
 
The question is ensuring that the default destructor of outer setting its INTERNAL pointer of i to nullptr instead of it being a noop and the destructor being elided for having no code.