public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110401] New: Unhelpful "goto is not a constant expression" in ill-formed constexpr function template
@ 2023-06-25  8:56 xry111 at gcc dot gnu.org
  2023-06-25 13:15 ` [Bug c++/110401] [10/11/12/13/14 Regression] Unhelpful "goto is not a constant expression" in ill-formed pre c++20 " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-06-25  8:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110401

            Bug ID: 110401
           Summary: Unhelpful "goto is not a constant expression" in
                    ill-formed constexpr function template
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xry111 at gcc dot gnu.org
  Target Milestone: ---

#include <array>

template <int N>
constexpr std::array<int, N> get_sqr()
{
    std::array<int, N> ret;
    for (int i = 0; i < N; i++)
        ret[i] = i * i;
    return ret;
}

constexpr auto sqr = get_sqr<10000>();

GCC says "error: 'goto' is not a constant expression".  This is puzzling
because there is no "goto" in the function.

Note that if it's not a template, GCC outputs the correct message:

#include <array>

constexpr std::array<int, 10000> get_sqr()
{
    std::array<int, 10000> ret;
    for (int i = 0; i < 10000; i++)
        ret[i] = i * i;
    return ret;
}

constexpr auto sqr = get_sqr();

t.cc: In function 'constexpr std::array<int, 10000> get_sqr()':
t.cc:5:28: error: uninitialized variable 'ret' in 'constexpr' function
    5 |     std::array<int, 10000> ret;
      |                            ^~~

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-22 13:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-25  8:56 [Bug c++/110401] New: Unhelpful "goto is not a constant expression" in ill-formed constexpr function template xry111 at gcc dot gnu.org
2023-06-25 13:15 ` [Bug c++/110401] [10/11/12/13/14 Regression] Unhelpful "goto is not a constant expression" in ill-formed pre c++20 " pinskia at gcc dot gnu.org
2023-07-07 10:45 ` [Bug c++/110401] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-03-22 13:43 ` law 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).