https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124389
Bug ID: 124389
Summary: [14/15/16 Regression] error: 'constexpr bool test(T)
[with T = Empty<int>]' used before its definition
since r14-4793-gdad311874ac3b3
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
CC: ppalka at gcc dot gnu.org
Target Milestone: ---
Taken from Bug 106067 comment 4:
The following code started failing on GCC 14.1 (also fails on GCC 15.2)
template <typename T> struct Empty {};
template <typename T>
constexpr bool test(T) noexcept { return true; }
template <typename T>
struct always_true {
static constexpr bool value = true;
static_assert(test(Empty<T>{}), "BUG");
};
template <typename T>
struct AAA {
template <typename U, bool = always_true<U>::value>
AAA(U) {}
};
template <int (*U) (AAA<int>)>
void test_function() {
auto r = U(AAA<int>(1));
}
int main() {
return 0;
}
The full error is:
<source>: In instantiation of 'struct always_true<int>':
<source>:15:50: required by substitution of 'template<class U, bool
<anonymous> > AAA<int>::AAA(U) [with U = int; bool <anonymous> = <missing>]'
15 | template <typename U, bool = always_true<U>::value>
| ^~~~~
<source>:21:16: required from here
21 | auto r = U(AAA<int>(1));
| ^~~~~~~~~~~
<source>:10:23: error: non-constant condition for static assertion
10 | static_assert(test(Empty<T>{}), "BUG");
| ~~~~^~~~~~~~~~~~
<source>:10:23: error: 'constexpr bool test(T) [with T = Empty<int>]' used
before its definition
Compiler returned: 1