public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56991] New: constexpr std::initializer_list crashes on too complex initialization
@ 2013-04-17 20:10 morwenn29 at hotmail dot fr
2013-04-18 7:50 ` [Bug c++/56991] constexpr std::initializer_list rejects " paolo.carlini at oracle dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: morwenn29 at hotmail dot fr @ 2013-04-17 20:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56991
Bug #: 56991
Summary: constexpr std::initializer_list crashes on too complex
initialization
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: morwenn29@hotmail.fr
I found some strange behaviour that, after a discussion on StackOverflow, seems
to be a bug (discussion here:
http://stackoverflow.com/questions/16057690/confusion-about-constant-expressions/16068953?noredirect=1#16068953).
It seems that GCC implements N3471 which means that every function of an
std::initializer_list are constexpr. When trying to pass simple constexpr
things in the initializer_list, it works fine:
#include <array>
#include <initializer_list>
int main()
{
constexpr std::array<int, 3> a = {{ 1, 2, 3 }};
constexpr int a0 = a[0];
constexpr int a1 = a[1];
constexpr int a2 = a[2];
constexpr std::initializer_list<int> b = { a0, a1, a2 };
return 0;
}
However, without the intermediate variables a0, a1 and a2, the example above
crashes:
#include <array>
#include <initializer_list>
int main()
{
constexpr std::array<int, 3> a = {{ 1, 2, 3 }};
constexpr std::initializer_list<int> b = { a[0], a[1], a[2] };
return 0;
}
The error is the following one:
error: 'const std::initializer_list<int>{((const int*)(&<anonymous>)), 3u}' is
not a constant expression
This last example works fine if I remove the constexpr qualifier at the
beginning of the line or if I replace the initializer_list by a std::array. It
seems that the bug is only triggered when using std::initializer_list with
constexpr.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/56991] constexpr std::initializer_list rejects too complex initialization
2013-04-17 20:10 [Bug c++/56991] New: constexpr std::initializer_list crashes on too complex initialization morwenn29 at hotmail dot fr
@ 2013-04-18 7:50 ` paolo.carlini at oracle dot com
2013-04-18 8:10 ` mizvekov at gmail dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-04-18 7:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56991
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|constexpr |constexpr
|std::initializer_list |std::initializer_list
|crashes on too complex |rejects too complex
|initialization |initialization
--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-04-18 07:50:36 UTC ---
I don't see the compiler *crashing*, I see it *rejecting* the snippet.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/56991] constexpr std::initializer_list rejects too complex initialization
2013-04-17 20:10 [Bug c++/56991] New: constexpr std::initializer_list crashes on too complex initialization morwenn29 at hotmail dot fr
2013-04-18 7:50 ` [Bug c++/56991] constexpr std::initializer_list rejects " paolo.carlini at oracle dot com
@ 2013-04-18 8:10 ` mizvekov at gmail dot com
2013-05-24 10:56 ` paolo.carlini at oracle dot com
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mizvekov at gmail dot com @ 2013-04-18 8:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56991
--- Comment #2 from Matheus Izvekov <mizvekov at gmail dot com> 2013-04-18 08:10:19 UTC ---
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
>From gcc-bugs-return-420518-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Apr 18 08:12:47 2013
Return-Path: <gcc-bugs-return-420518-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 11817 invoked by alias); 18 Apr 2013 08:12:47 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 11788 invoked by uid 48); 18 Apr 2013 08:12:44 -0000
From: "morwenn29 at hotmail dot fr" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/56991] constexpr std::initializer_list rejects too complex initialization
Date: Thu, 18 Apr 2013 08:12:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: morwenn29 at hotmail dot fr
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Changed-Fields:
Message-ID: <bug-56991-4-mPC2I6W6w1@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-56991-4@http.gcc.gnu.org/bugzilla/>
References: <bug-56991-4@http.gcc.gnu.org/bugzilla/>
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
Content-Type: text/plain; charset="UTF-8"
MIME-Version: 1.0
X-SW-Source: 2013-04/txt/msg01663.txt.bz2
Content-length: 285
http://gcc.gnu.org/bugzilla/show_bug.cgi?idV991
--- Comment #3 from Morwenn <morwenn29 at hotmail dot fr> 2013-04-18 08:12:44 UTC ---
(In reply to comment #1)
> I don't see the compiler *crashing*, I see it *rejecting* the snippet.
Indeed, sorry for the poor formulation.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/56991] constexpr std::initializer_list rejects too complex initialization
2013-04-17 20:10 [Bug c++/56991] New: constexpr std::initializer_list crashes on too complex initialization morwenn29 at hotmail dot fr
2013-04-18 7:50 ` [Bug c++/56991] constexpr std::initializer_list rejects " paolo.carlini at oracle dot com
2013-04-18 8:10 ` mizvekov at gmail dot com
@ 2013-05-24 10:56 ` paolo.carlini at oracle dot com
2014-08-29 13:10 ` paolo.carlini at oracle dot com
2014-08-29 13:12 ` paolo at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-05-24 10:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56991
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-05-24
Blocks| |54367
Ever confirmed|0 |1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/56991] constexpr std::initializer_list rejects too complex initialization
2013-04-17 20:10 [Bug c++/56991] New: constexpr std::initializer_list crashes on too complex initialization morwenn29 at hotmail dot fr
` (2 preceding siblings ...)
2013-05-24 10:56 ` paolo.carlini at oracle dot com
@ 2014-08-29 13:10 ` paolo.carlini at oracle dot com
2014-08-29 13:12 ` paolo at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-08-29 13:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56991
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |4.9.1
--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
This is fixed in 4.9.1 and mainline. I'm adding a reduced testcase and closing
the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/56991] constexpr std::initializer_list rejects too complex initialization
2013-04-17 20:10 [Bug c++/56991] New: constexpr std::initializer_list crashes on too complex initialization morwenn29 at hotmail dot fr
` (3 preceding siblings ...)
2014-08-29 13:10 ` paolo.carlini at oracle dot com
@ 2014-08-29 13:12 ` paolo at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: paolo at gcc dot gnu.org @ 2014-08-29 13:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56991
--- Comment #6 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-08-29 13:12 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-17 20:10 [Bug c++/56991] New: constexpr std::initializer_list crashes on too complex initialization morwenn29 at hotmail dot fr
2013-04-18 7:50 ` [Bug c++/56991] constexpr std::initializer_list rejects " paolo.carlini at oracle dot com
2013-04-18 8:10 ` mizvekov at gmail dot com
2013-05-24 10:56 ` paolo.carlini at oracle dot com
2014-08-29 13:10 ` paolo.carlini at oracle dot com
2014-08-29 13:12 ` paolo at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).