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]

Re: VLA/VM [*] bug fixes for C


Joseph S. Myers wrote:-

> for that case.  To quote my message:
> 
> Consider the code
> 
> 	int a, b, c, d, e, f;
> 	void *p1(void), *p2(void), *p3(void);
> 	int c1(void), c2(void);
> 	int d1(void), d2(void), d3(void);
> 	int z1(void), z2(void), z3(void);
> 
> 	int
> 	h(void)
> 	{
> 	  int r = (c1()
> 	           ? (z1(), (int (*(*(*)[d1()])[])[])p1())
> 	           : (c2()
> 	              ? (z2(), (int (*(*(*)[])[d2()])[])p2())
> 	              : (z3(), (int (*(*(*)[])[])[d3()])p3())
> 	             )
> 	          )[a][b][c][d][e][f];
> 	  return r;
> 	}
> 
> 	The outer conditional expression has a type which may informally be 
> 	described as "pointer to arrays [d1()] of pointers to arrays [d2()] of 
> 	pointers to arrays [d3()] of ints", by the composite type rules applied to 
> 	conditional expressions.  But when the expression is executed, all three 
> 	dimensions are needed to evaluate the [a][b][c][d][e][f] array reference, 
> 	but only one of the dimensions appears in an expression which should be 
> 	evaluated according to the rules for evaluation of conditional 
> 	expressions.  Furthermore, the return value of d2() may depend on the 
> 	prior calls to c2() and z2() in that part of the conditional expression, 
> 	so if c1() returns nonzero it might not suffice simply to evaluate d2() 
> 	and d3() as well as d1(); c2(), z2() and z3() would also need to be 
> 	evaluated.

My front end, and Comeau's oneline compiler, both give a similar
message:

"/tmp/foo.c", line 10: error: expression must point to a complete type
  int r = (c1()
          ^

which seems reasonable based on my understanding of composite types
of VLA types: that either satisfies the requirements of, and therefore
can be taken to be, the composite type.

Neil.


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