https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98804

--- Comment #1 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
Somewhat more reduced:

struct X { constexpr X(int&) {} };
template<X> struct Y {};

int a;
auto h(int b) -> Y<a>; // #1
auto h(int b) -> Y<b>; // #2

GCC accepts #1, but for #2 it produces seven (!) error messages:

<source>:6:21: error: template argument 1 is invalid
    6 | auto h(int b) -> Y<b>;
      |                     ^
<source>:6:21: error: template argument 1 is invalid
<source>:6:21: error: template argument 1 is invalid
<source>:6:21: error: template argument 1 is invalid
<source>:6:18: error: invalid template-id
    6 | auto h(int b) -> Y<b>;
      |                  ^
<source>:6:21: error: use of parameter outside function body before '>' token
    6 | auto h(int b) -> Y<b>;
      |                     ^
<source>:6:6: error: deduced class type 'Y' in function return type
    6 | auto h(int b) -> Y<b>;
      |      ^
<source>:2:20: note: 'template<X <anonymous> > struct Y' declared here
    2 | template<X> 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.)

Reply via email to