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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 61223
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61223&action=edit
gcc16-pr117783-wip.patch

My current WIP.
It can already handle something like
struct S { int a, b; long long c; unsigned d; };

template <typename ... T>
void
baz (T ...x)
{
}

template <typename T>
long long
foo ()
{
  auto [a, ...b, c] = T {};
  auto [...d] = T {};
  baz (d...);
  return ((a + c) + ... + b);
}

int
bar ()
{
  return foo <S> ();
}

Not really sure about mangling though.

LLVM mangles
struct S { int a, b; long long c; unsigned d; };

template <typename ... T>
void
baz (T ...x)
{
}

template <typename T>
long long
foo ()
{
  auto [a, ...b, c] = T {};
  auto [...d] = T {};
  baz (d...);
  return ((a + c) + ... + b);
}

int
bar ()
{
  return foo <S> ();
}
as
_ZZ3fooILi0EEvvEDC1a1bE and _ZZ3fooILi42EEvvEDC1a1bE (and so will this patch),
not really sure if the mangling shouldn't include something to say which of
those if any is a structured binding pack.

Another question is for
struct S { int a, b, c, d, e; };
int c[6];
struct B { template<int I> int &get () { return c[I]; } } b;
namespace std {
  template<typename T> struct tuple_size;
  template<int, typename> struct tuple_element;
}
template<> struct std::tuple_size<B> { static constexpr int value = 6; };
template<int I> struct std::tuple_element<I,B> { typedef int type; };

template <int N>
inline void
foo ()
{
  static auto [a, ...c, d] = b;
  ++a;
  ++d;
}

void
bar ()
{
  foo <0> ();
  foo <42> ();
}
where I see LLVM using
_ZZ3fooILi0EEvvE1c _ZGVZ3fooILi0EEvvE1c _ZZ3fooILi0EEvvE1c.1
_ZGVZ3fooILi0EEvvE1c.2 _ZZ3fooILi0EEvvE1c.3 _ZGVZ3fooILi0EEvvE1c.4 etc.
That just can't be right.

Reply via email to