[Bug libstdc++/87855] std::optional<T> only copy-constructible if T is trivially copy-constructible

ville.voutilainen at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Nov 19 12:06:00 GMT 2018


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

--- Comment #9 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
See https://wandbox.org/permlink/snAuT59ocie38DU5
Here's a tl;dr:

struct NonTrivial {NonTrivial(const NonTrivial&) {}};
struct X {
    X() : x(42) {} 
    X(bool b) : X(b ? X(42): X(666)) {} // clang doesn't like this
    X(int foo) : x(foo) {} 
    ~X() {} 
    union {int x; NonTrivial y;};
}; 

X is not copyconstructible in either gcc or clang, but gcc apparently
elides the copy in the call to the delegated constructor on the commented
line, whereas clang does not.


More information about the Gcc-bugs mailing list