public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "morwenn29 at hotmail dot fr" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-56991-4@http.gcc.gnu.org/bugzilla/> (raw)


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.


             reply	other threads:[~2013-04-17 20:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-17 20:10 morwenn29 at hotmail dot fr [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-56991-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).