This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/87855] std::optional<T> only copy-constructible if T is trivially copy-constructible
- From: "ville.voutilainen at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 19 Nov 2018 12:06:18 +0000
- Subject: [Bug libstdc++/87855] std::optional<T> only copy-constructible if T is trivially copy-constructible
- Auto-submitted: auto-generated
- References: <bug-87855-4@http.gcc.gnu.org/bugzilla/>
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.