https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128613
Bug ID: 128613
Summary: compiler rejects valid requires-expression constraint
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: irvsrc at gmail dot com
Target Milestone: ---
Example:
```
#include <utility>
template<typename t>
concept c = true;
template<typename t>
struct type;
template<typename t> // remove specialization = ok
requires(true)
struct type<t> {
auto constexpr static b1 = c<t>; // remove concept = ok
using ty = std::conditional_t<b1, int, int>;
template<ty>
auto constexpr static b2 = true;
template<ty v> // remove constraint = ok
requires(b2<v>) // error
auto static fn() { }
};
auto main() -> int {
type<int>::fn<10>();
}
```
Output:
```
<source>:19:18: error: the value of 'type<t>::b1' is not usable in a constant
expression [-Wtemplate-body]
19 | requires(b2<v>) // error
| ^
<source>:11:27: note: 'type<t>::b1' used in its own initializer
11 | auto constexpr static b1 = c<t>; // remove concept = ok
| ^~
<source>:19:18: note: in template argument for type 'bool'
19 | requires(b2<v>) // error
| ^
<source>: In function 'int main()':
<source>:24:22: error: no matching function for call to 'type<int>::fn<10>()'
24 | type<int>::fn<10>();
| ~~~~~~~~~~~~~~~~~^~
• there is 1 candidate
• candidate 1: 'template<std::conditional<true, int, int>::type v>
requires <erroneous-expression> static auto type<t>::fn() [with typename
std::conditional<b1, int, int>::type v = v; t = int]'
<source>:20:17:
20 | auto static fn() { }
| ^~
• template argument deduction/substitution failed:
• constraints not satisfied
Compiler returned: 1
```
GCC (trunk), -std=c++26