This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Break in loop expression-3
- From: Florian Weimer <fweimer at redhat dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: Alex Markin <alexanius at gmail dot com>, gcc-help at gcc dot gnu dot org
- Date: Wed, 24 Jul 2013 11:53:52 +0200
- Subject: Re: Break in loop expression-3
- References: <CAAgqtbVMXMHoCdasQ=ZWvatMtBwhkas5mo8=CgGgbjEjOvJRwA at mail dot gmail dot com> <CAKOQZ8yNOt0cR7SYP17ah5vTDyOQ7cQRMYkDrPV7Y3L6UaNWhg at mail dot gmail dot com>
On 07/12/2013 06:16 PM, Ian Lance Taylor wrote:
for(int i = 0;; ({break;}))
But probably you wanted to know whether it is a bug in LLVM or in GCC.
It's a bug in LLVM. You can't use break in a statement expression to
break out of a loop that is not in the statement expression.
Statement expressions are their own thing; they don't inherit the
surrounding context, except that using a goto statement to a label
outside the statement expression is permitted.
This is not what's implemented in GCC 4.8. This code compiles (both as
C and C++):
int
f()
{
int x = 1;
while (1) {
x = ({break; 5;});
}
return x;
}
The discrepancy between GCC and Clang is whether the expressions in the
for statement header are considered nested within the loop. I'm not
sure if these aspects of statement expressions can be considered fully
fleshed out.
--
Florian Weimer / Red Hat Product Security Team