Here we were parsing
template <typename T> struct C {
friend C(T::fn)(); // this
};
wrongly in C++2a since my P0634 patch. T::fn is actually a function
declaration, but cp_parser_constructor_declarator_p was thinking it's
a constructor. That function actually has code to prevent the compiler
from thinking that
S (f)(int);
is a constructor: it checks if after 'S' there's '(' followed by ')', '...',
or a type. If parsing the type succeeds, it looks like a ctor. In this
case it succeeded, because T::fn is a qualified name and we are parsing
a member-declaration, so CP_PARSER_FLAGS_TYPENAME_OPTIONAL was set.
We can either look further and say it's not a constructor if what comes
after "(T::fn)" is '('. Or we can prevent cp_parser_type_specifier from
assuming a type if friend_p, because while constructors can be friends,
they need to use a qualified-id, and at this point we know that the name
isn't qualified, so it can't be a valid friend constructor.
Bootstrapped/regtested on x86_64-linux, ok for trunk and 9?
2019-05-24 Marek Polacek <polacek@redhat.com>
PR c++/90572 - wrong disambiguation in friend declaration.
* parser.c (cp_parser_constructor_declarator_p): Don't allow missing
typename for friend declarations.