[libcxx-commits] [PATCH] D124516: [libc++] Implement `std::expected` P0323R12
Jonathan Wakely via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 1 06:47:03 PDT 2022
jwakely added inline comments.
================
Comment at: libcxx/include/__expected/expected.h:630-633
+ union {
+ _Tp __val_;
+ _Err __unex_;
+ };
----------------
huixie90 wrote:
> @jwakely Hi Jon, I have noticed that in libstdc++, there is a place holder type as the first type in the union
> https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/expected#L893
>
> I am trying to understand the purpose of that type. At the first glance, I thought it is for the case where `T` is not default constructible and we need that type in case we cannot initialise `T` directly in the `expected`'s constructor's initializer lists.
> It turns out that I was wrong and it is possible to have the union uninitialised even if `T` is not default constructible.
> https://godbolt.org/z/9xePvrE4x
>
> So I believe libstdc++ has that dummy type for other reasons. Could you please shed some lights on this?
> So I believe libstdc++ has that dummy type for other reasons. Could you please shed some lights on this?
I think it was necessary with older versions of GCC, but isn't needed now. It could be removed.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124516/new/
https://reviews.llvm.org/D124516
More information about the libcxx-commits
mailing list