This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Array-to-pointer conversion in cast expressions


Consider the following fragment:
void foo() {
  int a[2][2];
  typedef int (&P22)[2][2];
#ifdef NEW_STYLE_CAST
  static_cast<P22>(a);
#else
  (P22) a;
#endif
}

If you compile it with -DNEW_STYLE_CAST, it compiles fine.
if you compile it without, you get this error message:
  a1.cc:7: cannot convert `int (*)[2]' to `int[2][2]' in converting

What's happening, of course, is that when the compiler sees
the expression "(P22) a", it performs the array-to-pointer
conversion, so it's applying a cast to an operand of type
pointer-to-array-of-two-ints.  That cast is illegal, so the compiler
gives an error message.

I can't find any justification in the Standard for the compiler to
treat "(P22) a" and "static_cast<P22>(a)" differently.  So, the
usual questions:
 (1) Have I missed something, and is it correct for the compiler
       to be applying the array-to-pointer conversion for a C-
       style cast but not for static_cast?
 (2) If the answer to #1 is no: is this a known bug, e.g. one of
       the bugs in the "we'll see a fix with the new parser"
       category?

			--Matt


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]