public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/110401] [10/11/12/13/14 Regression] Unhelpful "goto is not a constant expression" in ill-formed pre c++20 constexpr function template
Date: Sun, 25 Jun 2023 13:15:07 +0000	[thread overview]
Message-ID: <bug-110401-4-rt1iKUw491@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110401-4@http.gcc.gnu.org/bugzilla/>

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Unhelpful "goto is not a    |[10/11/12/13/14 Regression]
                   |constant expression" in     |Unhelpful "goto is not a
                   |ill-formed pre c++20        |constant expression" in
                   |constexpr function template |ill-formed pre c++20
                   |                            |constexpr function template
   Last reconfirmed|                            |2023-06-25
   Target Milestone|---                         |10.5
             Status|UNCONFIRMED                 |NEW
      Known to fail|                            |7.3.0
      Known to work|                            |7.1.0, 7.2.0
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Compiling it with -std=c++11 is even worse as it does not show the reason:
```
<source>:12:36: error: 'constexpr std::array<int, N> get_sqr() [with int N =
10000]' called in a constant expression
   12 | constexpr auto sqr = get_sqr<10000>();
      |                      ~~~~~~~~~~~~~~^~
<source>:4:30: note: 'constexpr std::array<int, N> get_sqr() [with int N =
10000]' is not usable as a 'constexpr' function because:
    4 | constexpr std::array<int, N> get_sqr()
      |                              ^~~~~~~
```

GCC 7.1 and 7.2 used to have the correct explanation for C++11+:
```
<source>: In instantiation of 'constexpr std::array<int, N> get_sqr() [with int
N = 10000]':
<source>:12:37:   required from here
<source>:6:24: error: uninitialized variable 'ret' in 'constexpr' function
     std::array<int, N> ret;
                        ^~~
In file included from <source>:1:0:
/opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/array:94:12: note: 'struct
std::array<int, 10000>' has no user-provided default constructor
     struct array
            ^~~~~
/opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/array:110:56: note: and the
implicitly-defined constructor does not initialize 'int std::array<int,
10000>::_M_elems [10000]'
       typename _AT_Type::_Type                         _M_elems;
                                                        ^~~~~~~~
<source>:12:37: error: 'constexpr std::array<int, N> get_sqr() [with int N =
10000]' called in a constant expression
 constexpr auto sqr = get_sqr<10000>();
                                     ^
<source>:4:30: note: 'constexpr std::array<int, N> get_sqr() [with int N =
10000]' is not usable as a constexpr function because:
 constexpr std::array<int, N> get_sqr()
                              ^~~~~~~

```


GCC 7.3+ removed the "uninitialized variable 'ret' in 'constexpr' function".

GCC 10+ then removed the 2 notes at the beginning.


Note this is actually valid C++20 so maybe the change in GCC 10 is related to
that ...

  reply	other threads:[~2023-06-25 13:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-25  8:56 [Bug c++/110401] New: Unhelpful "goto is not a constant expression" in ill-formed " xry111 at gcc dot gnu.org
2023-06-25 13:15 ` pinskia at gcc dot gnu.org [this message]
2023-07-07 10:45 ` [Bug c++/110401] [11/12/13/14 Regression] Unhelpful "goto is not a constant expression" in ill-formed pre c++20 " 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-rt1iKUw491@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).