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

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).