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

--- Comment #3 from Jean-Michaƫl Celerier <jeanmichael.celerier at gmail dot 
com> ---
It worked in 11.2 and started failing in 11.3. 

Short repro: https://gcc.godbolt.org/z/GYYbrTdxh 


#include <boost/pfr.hpp>

template <class T, class F>
constexpr void for_each_field(T&& value, F&& func)
{
  using namespace boost::pfr;
  using namespace boost::pfr::detail;
  constexpr std::size_t fields_count_val =
fields_count<std::remove_reference_t<T>>();

  auto t = boost::pfr::detail::tie_as_tuple(value);

  [&]<std::size_t... I>(std::index_sequence<I...>)
  {
    (func(get<I>(t)), ...);
  }
  (std::make_index_sequence<fields_count_val>{});
}

constexpr int index_in_struct(const auto& s, auto... member)
{
  int index = -1;
  int k = 0;

  for_each_field(s, [&](auto& m) {
    if constexpr(requires { bool(&m == &(s.*....*member)); })
    {
      if(&m == &(s.*....*member))
      {
        index = k;
      }
    }
    ++k;
  });


  return index;
}

struct X
{
    int z;
};

int main()
{
    constexpr int r = index_in_struct(X{}, &X::z);
}

Reply via email to