https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98804
--- Comment #1 from Richard Smith ---
Somewhat more reduced:
struct X { constexpr X(int&) {} };
template struct Y {};
int a;
auto h(int b) -> Y; // #1
auto h(int b) -> Y; // #2
GCC accepts #1, but for #2 it produces seven (!) error messages:
:6:21: error: template argument 1 is invalid
6 | auto h(int b) -> Y;
| ^
:6:21: error: template argument 1 is invalid
:6:21: error: template argument 1 is invalid
:6:21: error: template argument 1 is invalid
:6:18: error: invalid template-id
6 | auto h(int b) -> Y;
| ^
:6:21: error: use of parameter outside function body before '>' token
6 | auto h(int b) -> Y;
| ^
:6:6: error: deduced class type 'Y' in function return type
6 | auto h(int b) -> Y;
| ^
:2:20: note: 'template > struct Y' declared here
2 | template struct Y {};
|^
As far as I'm aware, both #1 and #2 are valid. (I think the "use of parameter
outside function body" restriction is referring to [dcl.fct.default]/9, but
that refers only to uses of parameters within default arguments, not uses in
other contexts in the function declaration.)