This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]