https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128029
Bug ID: 128029
Summary: [9/10/11/12/13/14/15/16/17 Regression] literal
operator template with auto/dependent parameter
incorrectly accepted
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
template <auto V> int operator""_x ();
template <decltype(auto) V> int operator""_y ();
template<class T> struct S { template<T> friend int operator""_q(); };
S<int> a;
The following is accepted by GCC trunk, 16, 15, 14, 13, 12, 11, 10 and 9 with
-std=c++2a -pedantic-errors. GCC 8.5 states:
<source>:1:38: error: literal operator template 'int operator""_x()' has
invalid parameter list. Expected non-type template argument pack <char...> or
<typename CharT, CharT...>
template <auto V> int operator""_x ();
^
<source>:2:48: error: literal operator template 'int operator""_y()' has
invalid parameter list. Expected non-type template argument pack <char...> or
<typename CharT, CharT...>
template <decltype(auto) V> int operator""_y ();
^
<source>:3:67: error: literal operator template 'int operator""_q()' has
invalid parameter list. Expected non-type template argument pack <char...> or
<typename CharT, CharT...>
template<class T> struct S { template<T> friend int operator""_q(); };
^
...[over.literal] seems pretty direct in this regard - a bare auto or dependent
parameter cannot lay a claim to either the numeric or string template branches,
since it could also just deduce to e.g. int.
The code that handles this (in
cp_parser_template_declaration_after_parameters):
tree parm_list = TREE_VEC_ELT (parameter_list, 0);
tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);
if (TREE_CODE (parm) != PARM_DECL)
ok = false;
else if (MAYBE_CLASS_TYPE_P (TREE_TYPE (parm))
&& !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
/* OK, C++20 string literal operator template. We don't need
to warn in lower dialects here because we will have already
warned about the template parameter. */;
else if (TREE_TYPE (parm) != char_type_node
|| !TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))
ok = false;
...certainly seems suspicious - I figure the first `else if` perhaps should
have an extra clause to filter this out?