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

--- Comment #1 from m.cencora at gmail dot com ---
Here is another repoducer, that does not use std::variant:

#include <type_traits>
#include <utility>
#include <cstddef>

struct Base
{
    int a;

    template <typename F>
    static constexpr auto for_all_data_members(F&& func)
    {
        return func(&Base::a); 
    }
};

struct MyStruct
{
    int a;
    int b;
    Base c;

    template <typename F>
    static constexpr auto for_all_data_members(F&& func)
    {
        return func(
            &MyStruct::a
          , &MyStruct::b
#ifndef FIX_COMPILATION
          , &MyStruct::c
#endif
); 
    }
};

constexpr void serialize(int val)
{}

template <typename Class>
struct SerializeAll
{
    const Class & object;

    template <typename ...Args>
    constexpr void operator()(Args ...args)
    {
        (serialize(object.*args), ...);
    }
};

template <typename T>
constexpr void serialize(const T& obj)
{
    return T::for_all_data_members(SerializeAll<T>{obj});
}

constexpr bool test(const MyStruct& v)
{
    serialize(v);
    return true;
}

static_assert(test(MyStruct{}), "");

Reply via email to