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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And libc++'s std::variant is still affected by the same issue, but instead of
the default constructor being deleted it just has the wrong exception
specification:

#include <variant>

void testVarStruct()
{
    struct DataWithStruct {
        struct A {
            int number = 5; // compiles, if remove initialization
        };

        using Member = std::variant<A>;
        Member data;
        static_assert(std::is_nothrow_default_constructible_v<Member>);
    };
}

The difference is that GCC defines the std::variant default constructor as
defaulted, but libc++ defines it as:

constexpr variant()
noexcept(is_nothrow_default_constructible_v<variant_alternative<0, Types...>)

That means the constructor isn't deleted for libc++, it just has the wrong
noexcept-specifier.

It looks like the nested class DataWithStruct::A isn't considered complete
until after DataWithStruct is complete, but I'm not sure why that is.

Reply via email to