From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3658 invoked by alias); 17 Apr 2013 20:10:22 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 3619 invoked by uid 48); 17 Apr 2013 20:10:18 -0000 From: "morwenn29 at hotmail dot fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/56991] New: constexpr std::initializer_list crashes on too complex initialization Date: Wed, 17 Apr 2013 20:10:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new 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: 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/msg01637.txt.bz2 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 #include int main() { constexpr std::array a = {{ 1, 2, 3 }}; constexpr int a0 = a[0]; constexpr int a1 = a[1]; constexpr int a2 = a[2]; constexpr std::initializer_list b = { a0, a1, a2 }; return 0; } However, without the intermediate variables a0, a1 and a2, the example above crashes: #include #include int main() { constexpr std::array a = {{ 1, 2, 3 }}; constexpr std::initializer_list b = { a[0], a[1], a[2] }; return 0; } The error is the following one: error: 'const std::initializer_list{((const int*)(&)), 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.