https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90858
--- Comment #2 from m.cencora at gmail dot com ---
This bug exists since the beginning of C++11 constexpr support (gcc 4.7).
Here is a reproducer for C++11:
struct Base
{
int a;
template <typename F>
static constexpr int for_all_data_members(F&& func)
{
return func(&Base::a);
}
};
struct MyStruct
{
int a;
int b;
Base c;
template <typename F>
static constexpr int for_all_data_members(F&& func)
{
return func(
&MyStruct::a
, &MyStruct::b
#ifndef FIX_COMPILATION
, &MyStruct::c
#endif
);
}
};
constexpr int serialize(int val)
{
return 0;
}
template <typename Class>
struct SerializeAll
{
const Class & object;
template <typename ...Args>
constexpr int operator()(Args ...args)
{
using LtrExpander = int[];
return (LtrExpander{ serialize(object.*args)... }, 0);
}
};
template <typename T>
constexpr int serialize(const T& obj)
{
return T::for_all_data_members(SerializeAll<T>{obj});
}
constexpr bool test(const MyStruct& v)
{
return (serialize(v), true);
}
static_assert(test(MyStruct{}), "");