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