This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
C++ BUGS: comma operator
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: C++ BUGS: comma operator
- From: Nathan Sidwell <nathan at acm dot org>
- Date: Tue, 07 Sep 1999 10:50:13 +0100
- Reply-To: nathan at compsci dot bristol dot ac dot uk
Hi,
the attached two test case show some brokeness in the comma operator.
build_compound_expr is erroneously performing default conversions on its
RHS, should that be a function or array. I see no justification for this
behaviour in 5.18.
expr_sizeof (typeck.c) contains the following comment,
/* ANSI says arrays and functions are converted inside comma.
But we can't really convert them in build_compound_expr
because that would break commas in lvalues.
So do the conversion here if operand was a comma. */
I can find nothing about this in 5.3.3 or 5.18. 5.3.3 explicitly says
that such conversions do not happen. Anyway, build_compound_expr
contains the following
contradictory comment.
/* Convert arrays to pointers. */
The conditional operator does the right thing, but I include it for
completeness.
may I install them?
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
I have seen the death of PhotoShop -- it is called GIMP
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk
// Copyright (C) 1999 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 5 Sep 1999 <nathan@acm.org>
// C++ does not decay lvalues into rvalues until as late as possible. This
// means things like the rhs of a comma operator mustn't decay. This will make
// a difference if it is an array or function.
extern void abort();
int main (int argc, char **argv)
{
int ary[10];
int ary1[10];
if (sizeof (0,ary) != sizeof (ary))
abort ();
if (sizeof (argc ? ary : ary1) != sizeof (ary))
abort ();
return 0;
}
// Build don't link:
// Copyright (C) 1999 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 5 Sep 1999 <nathan@acm.org>
// C++ does not decay lvalues into rvalues until as late as possible. This
// means things like the rhs of a comma operator mustn't decay. This will make
// a difference if it is an array or function.
struct S;
struct T {int m;};
extern S s; // an incomplete
extern S arys[20]; // an incomplete array
extern T aryt[]; // an incomplete array;
void fn () {}
int main (int argc, char **argv)
{
sizeof (s); // ERROR - incomplete
sizeof (0, s); // ERROR - incomplete
sizeof (argc ? s : s); // ERROR - incomplete
sizeof (arys); // ERROR - incomplete
sizeof (0, arys); // ERROR - incomplete
sizeof (argc ? arys : arys); // ERROR - incomplete
sizeof (aryt); // ERROR - incomplete
sizeof (0, aryt); // ERROR - incomplete
sizeof (argc ? aryt : aryt); // ERROR - incomplete
sizeof (fn); // ERROR - cannot take size of function
sizeof (0, fn); // ERROR - cannot take size of function
sizeof (argc ? fn : fn); // ERROR - cannot take size of function
sizeof (&fn); // ok
sizeof (0, &fn); // ok
sizeof (argc ? &fn : &fn); // ok
return 0;
}