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

            Bug ID: 127276
           Summary: P3598R0 testcase fails to compile
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

The P3598R0 paper testcase clearly contains a lot of bugs, but if I try to fix
them all and remove the contracts, it is incorrectly rejected by g++ 16/trunk,
but works correctly with the clang++ reflection branch.

// { dg-do compile { target c++26 } }
// { dg-additional-options "-freflection" }

#include <array>
#include <map>
#include <meta>
#include <vector>

template <typename T1, typename T2>
auto
foo (const T1 &t1, const T2 &t2)
{
  constexpr auto key = is_integral_type (^^T1) ? ^^t1 : ^^t2;
  constexpr auto container = is_integral_type (^^T1) ? ^^t2 : ^^t1;
  return [: container :][ [: key :] ];
}

void
bar (std::vector <int> &v)
{
  foo (v, 5);
  foo (5, v);
}

template <std::size_t N>
void
baz (std::array <int, N> &v)
{
  foo (v, 5);
  foo (5, v);
}

void
qux (std::map <int, int> &m)
{
  foo (m, 5); // { dg-error "" }
  foo (5, m); // { dg-error "" }
}

void
corge (std::array <int, 7> &v)
{
  baz (v);
}

See https://godbolt.org/z/xzrzrfEfe ; the 2 calls in qux are correctly rejected
by clang++,  no viable overloaded operator[] for type 'const std::map<int,
int>'
but g++ emits
error: subscripted value is neither array nor pointer
for all the calls, not just with map.  Seems tsubst_expr on the ARRAY_REF with
SPLICE_EXPR as both operands results in build_x_array_ref on the REFERENCE_TYPE
PARM_DECLs directly rather than convert_from_reference of those, even when they
have reference type.

Reply via email to