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