https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88548
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2018-12-19
CC| |jason at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The problem I see is that we don't really pass the information that it is a
static member function rather than member function through the parser:
#1 0x0000000000a2df0e in cp_parser_late_return_type_opt
(parser=0x7ffff7ff6ab0, declarator=0x33153f0,
requires_clause=@0x7fffffffd378: <tree 0x0>, quals=0) at
../../gcc/cp/parser.c:21466
#2 0x0000000000a2c2a7 in cp_parser_direct_declarator (parser=0x7ffff7ff6ab0,
dcl_kind=CP_PARSER_DECLARATOR_NAMED, flags=32,
ctor_dtor_or_conv_p=0x7fffffffd5b4, member_p=true, friend_p=false) at
../../gcc/cp/parser.c:20645
#3 0x0000000000a2bf81 in cp_parser_declarator (parser=0x7ffff7ff6ab0,
dcl_kind=CP_PARSER_DECLARATOR_NAMED, flags=32,
ctor_dtor_or_conv_p=0x7fffffffd5b4, parenthesized_p=0x0, member_p=true,
friend_p=false) at ../../gcc/cp/parser.c:20472
#4 0x0000000000a33fe4 in cp_parser_member_declaration (parser=0x7ffff7ff6ab0)
at ../../gcc/cp/parser.c:24387
where cp_parser_member_declaration knows this information
(decl_specifiers.storage_class == sc_static), but
cp_parser_declarator/cp_parser_direct_declarator/cp_parser_late_return_type_opt
don't. Similarly for the noexcept:
#1 0x0000000000a3510e in cp_parser_noexcept_specification_opt
(parser=0x7ffff7ff6ab0, require_constexpr=true, consumed_expr=0x0,
return_cond=false) at ../../gcc/cp/parser.c:24961
#2 0x0000000000a352bc in cp_parser_exception_specification_opt
(parser=0x7ffff7ff6ab0) at ../../gcc/cp/parser.c:25023
#3 0x0000000000a2c245 in cp_parser_direct_declarator (parser=0x7ffff7ff6ab0,
dcl_kind=CP_PARSER_DECLARATOR_NAMED, flags=32,
ctor_dtor_or_conv_p=0x7fffffffd5b4, member_p=true, friend_p=false) at
../../gcc/cp/parser.c:20636
#4 0x0000000000a2bf81 in cp_parser_declarator (parser=0x7ffff7ff6ab0,
dcl_kind=CP_PARSER_DECLARATOR_NAMED, flags=32,
ctor_dtor_or_conv_p=0x7fffffffd5b4, parenthesized_p=0x0, member_p=true,
friend_p=false) at ../../gcc/cp/parser.c:20472
#5 0x0000000000a33fe4 in cp_parser_member_declaration (parser=0x7ffff7ff6ab0)
at ../../gcc/cp/parser.c:24387
We could say change member_p from bool to enum { NONMEMBER, MEMBER,
STATIC_MEMBER }; or similar. But then there is also a problem how to make the
diagnostic user friendly. Because, if I just return in the debugger in
inject_this_parameter in the third and fourth case, I get:
pr88548.C:5:33: error: invalid use of ‘this’ at top level
5 | static auto m3 () -> decltype(this->a) { return 0; }
| ^~~~
pr88548.C:5:33: error: invalid use of ‘this’ at top level
pr88548.C:6:39: error: invalid use of ‘this’ at top level
6 | static void m4 () noexcept(noexcept(this->a)) { }
| ^~~~
errors (for some reason the first one twice), while clang++/icpc talk about
this not being available in static member functions.
finish_this_expr has nice diagnostics:
2643 tree fn = current_nonlambda_function ();
2644 if (fn && DECL_STATIC_FUNCTION_P (fn))
2645 error ("%<this%> is unavailable for static member functions");
2646 else if (fn)
2647 error ("invalid use of %<this%> in non-member function");
2648 else
2649 error ("invalid use of %<this%> at top level");
but to get the 2645 diagnostics current_function_decl needs to be built and
marked as static member, which is something we don't have when parsing the late
return type or noexcept.