[Bug c++/87016] std::optional::operator= in constexpr context

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Aug 20 10:26:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87016

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The code is valid. The optional<T>::operator=(U&&) assignment operator is not
used when is_scalar<T> and is_same<T, decay_T<U>> (which is true here, where
T=int and U=int).

That means the assignment creates a temporary optional<int> using the constexpr
constructor, i.e.

  bar = std::optional<int>(10);

This is valid in a constexpr function.


More information about the Gcc-bugs mailing list