[Bug c++/70741] New: segfault when jumping into statement expression in array initializer
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70741 Bug ID: 70741 Summary: segfault when jumping into statement expression in array initializer Product: gcc Version: 5.2.1 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: donald.chai at synopsys dot com Target Milestone: --- Preface: 1) Apologies if this is the wrong component. 2) Yes, this code is crazy. I was testing our own compiler. :) GCC 5.x segfaults on the below code in C++ mode. $ cat test.c void testE_statement() { int x[10] = { ({ L: 0; }) }; goto L; } $ gcc-5 -c test.c test.c: In function ‘testE_statement’: test.c:5:5: error: jump into statement expression goto L; ^ test.c:3:12: note: label ‘L’ defined here ({ L: 0; }) $ gcc-5 -c -x c++ test.c test.c: In function ‘void testE_statement()’: test.c:1:6: internal compiler error: Segmentation fault void testE_statement() { ^ Please submit a full bug report, with preprocessed source if appropriate. See for instructions. $ gcc-5 --version gcc-5 (Ubuntu 5.2.1-23ubuntu1~12.04) 5.2.1 20151031 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. GCC 4.9 appears to do something somewhat reasonable: $ cat test.cpp #include int main() { int iters = 0; int x[10] = { ({ printf("0\n"); iters; }), ({ L: iters++; printf("1\n"); iters; }) }; if (iters < 2) goto L; printf("x[0]: %d\n", x[0]); printf("x[1]: %d\n", x[1]); } $ gcc-4.9 test.cpp $ ./a.out 0 1 1 x[0]: 0 x[1]: 2
[Bug c++/70744] New: preincrements possibly double-evaluated in GNU ternaries
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70744 Bug ID: 70744 Summary: preincrements possibly double-evaluated in GNU ternaries Product: gcc Version: 5.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: donald.chai at synopsys dot com Target Milestone: --- GCC, in C++ mode, appears to evaluate pre-increments twice in GNU ternaries: $ gcc-5 --version gcc-5 (Ubuntu 5.2.1-23ubuntu1~12.04) 5.2.1 20151031 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ cat test.c int main() { int x = 1; ++x ?: 1337; return x; } $ gcc-5 -x c test.c; ./a.out; echo $? 2 $ gcc-5 -x c++ test.c; ./a.out; echo $? 3 Clang appears to work: $ clang --version Ubuntu clang version 3.4-1ubuntu3~precise2 (tags/RELEASE_34/final) (based on LLVM 3.4) Target: x86_64-pc-linux-gnu Thread model: posix $ clang -x c++ test.c; ./a.out; echo $? test.c:3:5: warning: expression result unused [-Wunused-value] ++x ?: 1337; ^~~ 1 warning generated. 2
[Bug c++/70744] preincrements possibly double-evaluated in GNU ternaries
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70744 --- Comment #5 from Donald Chai --- For what it's worth, post-increments behave as I would expect: $ cat test.c int main() { int x = 1; x++ ?: 0xbeef; return x; } $ gcc-5 -x c test.c; ./a.out; echo $? 2 $ gcc-5 -x c++ test.c; ./a.out; echo $? 2