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]

Re: GCC's statement expression extension



    In message <Pine.SOL.4.21.0007220011570.29830-100000@orange.csi.cam.ac.uk>you
   write:
    > It seems GCC does not restrict gotos in and out of statement expressions,
    > even where they don't particularly make sense.  For example, the
    > nonsensical program
    > 
    > 	#include <stdio.h>
    > 	int main(void){ printf ("%d\n", ({a:; 0; })); goto a; }
    > 
    > dumps core for me on i686-pc-linux-gnu (after printing 0 many times).

This should definitely be illegal.  In general, statement-expressions
are a poorly thought out extension, and do not have nice semantics.
This is hardly the first oddity of these beasts.  (For example, it's
very hard to implement statement expressions as default arguments in
C++, which means that certainly default argument expressions involving
standard library functions do not work in G++.  Another C++ example is
that object-lifetime with statement expressions is not well-defined,
and has no obviously correct choice.)

Note that there is a similar problem:

  a:
     f ("%d\n", ({goto a;})

Basically, a jump into or out of a call is going to leave the stack
messed up.

The best solution would be to treat all labels in a
statement-expression as local, and to forbid any goto that leaves the
scope of a statement epxression.

A secondary consideration is that we should consider deprecating the
statement-expression extension.  We should try to convince the glibc
people that statement-expressions are bad, since they are the heaviest
users of this hack.  The glibc people should remove all of that crud
in macros, and replace it with inline functions.  And we should make
the compiler optimize the inline fucntions appropriately so that they
cannot complain that performance is degraded.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

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