https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120555
Bug ID: 120555
Summary: [Possible 15 Regression ] Use of auto func before
deduction of auto
Product: gcc
Version: 15.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gcc at hazardy dot de
Target Milestone: ---
The Code (https://gcc.godbolt.org/z/eaYddz3bW):
#include <array>
#include <concepts>
template<typename T>
constexpr auto func() {
if constexpr ( std::same_as<T, std::array<int, 2>> ) {
static constexpr std::array<int, 2> ret{23, 42};
return ret;
} else {
static constexpr auto ret = func<std::array<int, 2>>();
return std::pair{ret.begin(), ret.end()};
}
}
Runs fine with GCC 14.3 and clang, but with GCC 15.1 not. With -Wtemplate-body
the error message is:
<source>: In function 'constexpr auto func()':
<source>:10:61: error: use of 'constexpr auto func() [with T = std::array<int,
2>]' before deduction of 'auto' [-Wtemplate-body]
10 | static constexpr auto ret = func<std::array<int, 2>>();
| ~~~~~~~~~~~~~~~~~~~~~~~~^~
<source>:10:61: error: use of 'constexpr auto func() [with T = std::array<int,
2>]' before deduction of 'auto' [-Wtemplate-body]
And with -Wno-tempalte-body:
<source>: In instantiation of 'constexpr auto func() [with T = std::array<int,
2>]':
<source>:10:61: required from here
10 | static constexpr auto ret = func<std::array<int, 2>>();
| ~~~~~~~~~~~~~~~~~~~~~~~~^~
<source>:5:16: error: instantiating erroneous template
5 | constexpr auto func() {
| ^~~~
<source>:10:61: note: first error appeared here
10 | static constexpr auto ret = func<std::array<int, 2>>();
| ~~~~~~~~~~~~~~~~~~~~~~~~^~
Is this invalid code, which just got accepted before, or is it a bug?