https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87016
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to bobogu from comment #2) > Do I understand it correctly that this will get optimized into one statement > saying > > bar = std::optional<int>(10); No, it's not an optimization. When you assign an int to optional<int> it is equivalent to constructing a temporary optional<int> and then assigning that to the left-hand operand. > If so, is there something that could prevent such optimizations in order to > check if the code is portable? It's not an optimization, it's the required behaviour according the the specification of std::optional in the standard. > Also, just to clarify, this has nothing to do with this proposal > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0602r3.html to > which someone has pointed me to? It's nothing to do with that.