[Bug c++/126943] New: "template argument 1 is invalid" error on using function parameter in type requirement
cmingyi01 at gmail dot com via Gcc-bugs <[email protected]>
| Newsgroups | gmane.comp.gcc.bugs |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126943
Bug ID: 126943
Summary: "template argument 1 is invalid" error on using
function parameter in type requirement
Product: gcc
Version: 16.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: cmingyi01 at gmail dot com
Target Milestone: ---
The following valid C++20 code is rejected by GCC:
```
template <int> class C;
constexpr int g(auto const&) { return 0; }
template <class T>
int f(T a)
requires requires { typename C<g(a)>; }
{ return 0; }
int i = f(0);
```
Output:
```
<source>:6:36: error: template argument 1 is invalid
6 | requires requires { typename C<g(a)>; }
| ^
<source>:6:36: error: template argument 1 is invalid
<source>:6:36: error: template argument 1 is invalid
<source>:6:36: error: template argument 1 is invalid
<source>:6:36: error: template argument 1 is invalid
<source>:6:36: error: template argument 1 is invalid
<source>:6:36: error: template argument 1 is invalid
<source>:6:30: error: 'C' is not a type
6 | requires requires { typename C<g(a)>; }
| ^
<source>:9:10: error: no matching function for call to 'f(int)'
9 | int i = f(0);
| ~^~~
• there is 1 candidate
• candidate 1: 'template<class T> int f(T) requires
<erroneous-expression>'
<source>:5:5:
5 | int f(T a)
| ^
• template argument deduction/substitution failed:
• constraints not satisfied
```
See https://compiler-explorer.com/z/jdczc8Kz6.