Using gcc 4.8.0 20120923 (experimental) and compiler flags -Wall -pedantic -std=c++11 the following code gives an ICE: //------------- struct array { int data[1]; constexpr const int& at(unsigned i) { return (i < 1 ? 0 : throw 1), data[i]; //return i < 1 ? data[i] : (throw 0, data[i]); // OK } }; int main() { constexpr array a{}; constexpr int i = a.at(0); } //------------- " main.cpp||In function 'int main()':| main.cpp|12| in constexpr expansion of 'a.array::at(0u)'| main.cpp|12|internal compiler error: in adjust_temp_type, at cp/semantics.c:6425| " The code should be accepted.
Happens also with 4.7 HEAD.
Created attachment 28325 [details] gcc48-pr54777.patch Untested fix. Guess at least 4.7 and perhaps also 4.6 should get the fix.
Author: jakub Date: Wed Oct 3 14:21:20 2012 New Revision: 192036 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192036 Log: PR c++/54777 * semantics.c (cxx_eval_constant_expression) <case COMPOUND_EXPR>: If not ignoring the second operand, pass the original second operand and not one with stripped nops to cxx_eval_constant_expression. * g++.dg/cpp0x/constexpr-ref4.C: New test. Added: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-ref4.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/semantics.c trunk/gcc/testsuite/ChangeLog
Author: jakub Date: Wed Oct 3 14:27:30 2012 New Revision: 192037 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192037 Log: PR c++/54777 * semantics.c (cxx_eval_constant_expression) <case COMPOUND_EXPR>: If not ignoring the second operand, pass the original second operand and not one with stripped nops to cxx_eval_constant_expression. * g++.dg/cpp0x/constexpr-ref4.C: New test. Added: branches/gcc-4_7-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-ref4.C Modified: branches/gcc-4_7-branch/gcc/cp/ChangeLog branches/gcc-4_7-branch/gcc/cp/semantics.c branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Fixed for 4.7+.
*** Bug 55537 has been marked as a duplicate of this bug. ***