https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118139
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> --- pp_cxx_nested_name_specifier shouldn't be calling pp_cxx_unqualified_id for DECLTYPE_TYPE; it should handle a computed-type-specifier specifically. With the following patch we print 118139.C:6:15: error: ‘static void CW<T>::operator=(int) requires requires(typename decltype(T())::type x) {x;}’ must be a non-static member function [-Wtemplate-body] 6 | static void operator=(int) requires requires(V x) { x; } {} | ^~~~~~~~ --- a/gcc/cp/cxx-pretty-print.cc +++ b/gcc/cp/cxx-pretty-print.cc @@ -234,8 +234,12 @@ pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t) } /* nested-name-specifier: - class-or-namespace-name :: nested-name-specifier(opt) - class-or-namespace-name :: template nested-name-specifier */ + :: + type-name :: + namespace-name :: + computed-type-specifier :: + nested-name-specifier identifier :: + nested-name-specifier templateopt simple-template-id :: */ static void pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t) @@ -252,7 +256,11 @@ pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t) tree scope = get_containing_scope (t); pp_cxx_nested_name_specifier (pp, scope); pp_cxx_template_keyword_if_needed (pp, scope, t); - pp_cxx_unqualified_id (pp, t); + /* This is a computed-type-specifier. */ + if (TREE_CODE (t) == PACK_INDEX_TYPE || TREE_CODE (t) == DECLTYPE_TYPE) + pp->type_id (t); + else + pp_cxx_unqualified_id (pp, t); pp_cxx_colon_colon (pp); } }