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