Bug 54777 - [C++11] Comma operator in constexpr environment can cause ICE
Summary: [C++11] Comma operator in constexpr environment can cause ICE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.6.4
Assignee: Jakub Jelinek
URL:
Keywords: ice-on-valid-code
: 55537 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-10-02 08:21 UTC by Daniel Krügler
Modified: 2012-11-29 21:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-10-02 00:00:00


Attachments
gcc48-pr54777.patch (670 bytes, patch)
2012-10-02 10:18 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Krügler 2012-10-02 08:21:58 UTC
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.
Comment 1 Marek Polacek 2012-10-02 09:08:18 UTC
Happens also with 4.7 HEAD.
Comment 2 Jakub Jelinek 2012-10-02 10:18:27 UTC
Created attachment 28325 [details]
gcc48-pr54777.patch

Untested fix.  Guess at least 4.7 and perhaps also 4.6 should get the fix.
Comment 3 Jakub Jelinek 2012-10-03 14:21:24 UTC
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
Comment 4 Jakub Jelinek 2012-10-03 14:27:35 UTC
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
Comment 5 Jakub Jelinek 2012-10-03 14:31:35 UTC
Fixed for 4.7+.
Comment 6 Paolo Carlini 2012-11-29 21:28:13 UTC
*** Bug 55537 has been marked as a duplicate of this bug. ***