array decays too fast.

Nathan Myers ncm@nospam.cantrip.org
Wed Aug 12 20:58:00 GMT 1998


In egcs-2.91.50, the type of an array decays too readily
to a pointer, so that a conversion from T to const T& fails,
and template type matching fails.  (EDG-2.38 accepts this code.)

I would have expected the cast to be unnecessary, but
even EDG doesn't accept it without the cast.

Nathan Myers

egcs -c refmatch.cc
----------------------------------------
struct A { };

template <unsigned N>
  unsigned f(const A (& aa)[N])  { return N; }

int main()
{
  A aa[3];
  typedef const A (& CAR)[3];
  (CAR)aa;
  return f((CAR)aa) != 3;
}
-----------------------------------------
refmatch.cc: In function `int main()':
refmatch.cc:10: converting to `A[3]' from `A *'
refmatch.cc:11: converting to `A[3]' from `A *'



More information about the Gcc mailing list