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]

C++ frontend bug involving pointers to arrays


Hello,

there appears to be a bug in the handling of pointers to arrays of 
unspecified length as struct members in the C++ frontend.

The following testcase fails to compile with the error:
error: cannot convert `int (*)[0]' to `int (*)[]' in assignment
which appears to indicate that the type of the member 'a'
of 'struct test' was incorrectly determined.

Using a semantically equivalent workaround with typedef
makes the program work.  Both variants work when compiled
with the C frontend.

struct test
{
#ifndef WORKAROUND
  int (*a)[];
#else
  typedef int int_array[];
  int_array *a;
#endif
};
 
void test(void)
{
  struct test s;
  int (*a)[];
 
  a = s.a;
}


>From my preliminary analysis, the bug seems to be caused by this 
snippet in grokdeclarator (cp/decl.c), which doesn't distinguish
between an array and a pointer to array:

>            /* VC++ spells a zero-sized array with [].  */
>            if (size == NULL_TREE && decl_context == FIELD && ! staticp
>                && ! RIDBIT_SETP (RID_TYPEDEF, specbits))
>              size = integer_zero_node;

I'm not familiar enough with the C++ frontend to fix this, however.
Any suggestions?

(B.t.w. why is this non-standard VC++ compatibility feature enabled
even in strict standard mode?)

Thanks,
Ulrich

-- 
  Dr. Ulrich Weigand
  weigand@informatik.uni-erlangen.de


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