On 27/04/2026 15:10, Andrey Tarasevich wrote:
On Mon 4/27/2026 5:47 AM, Andrey Tarasevich wrote:
My guess would be that it is caused by your payload class having no
user-defined constructor. This causes any kind of default
initialization to turn into value-initialization requiring everything
to be zeroed out.
If you add an explicit "do nothing" user-defined constructor this
behavior will probably go away. Of course, if the struct is declared
in the C side, this might require jumping through some hoops...
Exactly!
... although the above does not answer the question of why GCC would try
to apply _any_ kind of initialization to the inactive payload in `std::optional` (even if it helps to suppress it).
Yes, that's what I am curious about.
For now, at least, I've made a "home-made" optional that works fine for
the purpose. It doesn't have all the features of the standard type in
the face of different requirements for moves, copies, etc., but it's
fine for POD structs pulled in from the C world. (I don't think they
are called POD any more with that latest C++ standards, but I think it
is clear what I mean.)
--- PyGate Linux v1.5.14
* Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)