c++/reflection: ICE with &template [:members_of():] [PR124794]

Given

  struct C { template <class T> void f(T); };

we handle "&template [:^^C::f:]" correctly because the spliced
expression is

  BASELINK<OVERLOAD<TEMPLATE_DECL f>>, binfo C>

which is fine: we have an OVERLOAD around the TEMPLATE_DECL and
lookup_member wrapped the whole thing in a BASELINK.  But when
we're splicing members_of(^^C, ac)[0], we ended up with

  OVERLOAD<TEMPLATE_DECL f>>

and then go down the wrong path in cp_parser_splice_expression.

splice already correctly adds the missing OVERLOAD but it also
needs to (maybe) add a BASELINK.

This patch also adjusts baselink_for_fns to gain a parameter
controlling if we want to ignore currently_open_derived_class.
It matters when we're in a member function of a class derived
from C and the object argument of the -> is a different derived class,
as exercised in splice17.C: pd->[:g1:] (42); in D2::mfn.  There, if
we didn't ignore currently_open_derived_class, the BASELINK would
use D2 as the access_binfo, which is wrong because it has no
derivation relationship to the object type (here D1).  With this
patch access_binfo will be C, which is what members_of gave us.

	PR c++/124794

gcc/cp/ChangeLog:

	* cp-tree.h (baselink_for_fns): Adjust declaration.
	* parser.cc (cp_parser_reflect_expression): Adjust the call to
	baselink_for_fns.
	* reflect.cc (splice): Call baselink_for_fns.
	* semantics.cc (baselink_for_fns): Add a bool parameter.  If
	it's true, ignore currently_open_derived_class.

gcc/testsuite/ChangeLog:

	* g++.dg/reflect/splice17.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
5 files changed