| Summary: | constexpr std::initializer_list rejects too complex initialization | ||
|---|---|---|---|
| Product: | gcc | Reporter: | Morwenn <morwenn29> |
| Component: | c++ | Assignee: | Not yet assigned to anyone <unassigned> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | daniel.kruegler, mizvekov |
| Priority: | P3 | ||
| Version: | 4.8.0 | ||
| Target Milestone: | 4.9.1 | ||
| URL: | http://stackoverflow.com/q/16057690/1364752 | ||
| Host: | Target: | ||
| Build: | Known to work: | ||
| Known to fail: | 4.6.4, 4.7.2, 4.7.3, 4.8.0, 4.8.1 | Last reconfirmed: | 2013-05-24 00:00:00 |
| Bug Depends on: | |||
| Bug Blocks: | 55004 | ||
|
Description
Morwenn
2013-04-17 20:10:17 UTC
I don't see the compiler *crashing*, I see it *rejecting* the snippet. I get also a similar bug:
#include <initializer_list>
//is accepted by gcc
constexpr std::initializer_list<int> good1 = { 1, 2, 3 };
struct foo { int a, b; };
//still ok
constexpr foo good2 = { 1, 2 };
//gcc rejects this
constexpr std::initializer_list<foo> bad = { { 1, 2 }, { 3, 4} };
Compiling this gives a similar error:
test.cc:12:64: error: ‘const std::initializer_list<foo>{((const foo*)(& _ZGRL3bad0)), 2u}’ is not a constant expression
(In reply to comment #1) > I don't see the compiler *crashing*, I see it *rejecting* the snippet. Indeed, sorry for the poor formulation. (In reply to Matheus Izvekov from comment #2) > I get also a similar bug: > > #include <initializer_list> > > //is accepted by gcc > constexpr std::initializer_list<int> good1 = { 1, 2, 3 }; > > struct foo { int a, b; }; > > //still ok > constexpr foo good2 = { 1, 2 }; > > //gcc rejects this > constexpr std::initializer_list<foo> bad = { { 1, 2 }, { 3, 4} }; A variation of the last line also produces the same error: constexpr std::initializer_list<foo> bad2 = { good2, good2 }; I can confirm that the error also occurs for the trunk, tested with gcc 4.9.0 20130519 (experimental). This is fixed in 4.9.1 and mainline. I'm adding a reduced testcase and closing the bug. Author: paolo Date: Fri Aug 29 13:12:02 2014 New Revision: 214729 URL: https://gcc.gnu.org/viewcvs?rev=214729&root=gcc&view=rev Log: 2014-08-29 Paolo Carlini <paolo.carlini@oracle.com> PR c++/56991 * g++.dg/cpp0x/constexpr-56991.C: New. Added: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-56991.C Modified: trunk/gcc/testsuite/ChangeLog |