public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "xry111 at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/110401] New: Unhelpful "goto is not a constant expression" in ill-formed constexpr function template
Date: Sun, 25 Jun 2023 08:56:41 +0000	[thread overview]
Message-ID: <bug-110401-4@http.gcc.gnu.org/bugzilla/> (raw)

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;
      |                            ^~~

             reply	other threads:[~2023-06-25  8:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-25  8:56 xry111 at gcc dot gnu.org [this message]
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

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