c++: non-dep call with empty TYPE_BINFO [PR105758]

Here the out-of-line definition of Z<T>::z causes duplicate_decls to
change z's type from using the primary template type Z<T> (which is also
the type of the injected class name) to the implicit instantiation Z<T>,
and this latter type lacks a TYPE_BINFO (although its TYPE_CANONICAL was
set by a special case in lookup_template_class to point to the former).

Later, when processing the non-dependent call z->foo(0), build_over_call
relies on the object argument's TYPE_BINFO to build the templated form
for this call, which fails because the object argument type has empty
TYPE_BINFO due to the above.

It seems weird that the implicit instantiation Z<T> doesn't have the
same TYPE_BINFO as the primary template type Z<T>, despite them being
proclaimed equivalent via TYPE_CANONICAL.  So I tried also setting
TYPE_BINFO in the special case in lookup_template_class, but that led to
some problems with constrained partial specializations of the form Z<T>.
I'm not sure what, if anything, we ought to do about the subtle
differences between these two versions of the same type.

Fortunately it seems we don't need to rely on TYPE_BINFO at all in
build_over_call here -- the z_candidate struct already contains the
exact binfos we need to rebuild the BASELINK for the templated form.

	PR c++/105758

gcc/cp/ChangeLog:

	* call.cc (build_over_call): Use z_candidate::conversion_path
	and ::access_path instead of TYPE_BINFO when building the
	BASELINK for the templated form.

gcc/testsuite/ChangeLog:

	* g++.dg/template/non-dependent24.C: New test.
This commit is contained in:
Patrick Palka 2022-05-31 16:49:08 -04:00
parent 3f7daf7ec7
commit 4f84f12066
2 changed files with 21 additions and 2 deletions

View File

@ -9244,8 +9244,8 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
}
else
{
tree binfo = TYPE_BINFO (TREE_TYPE (first_arg));
callee = build_baselink (binfo, binfo, fn, NULL_TREE);
callee = build_baselink (cand->conversion_path, cand->access_path,
fn, NULL_TREE);
callee = build_min (COMPONENT_REF, TREE_TYPE (fn),
first_arg, callee, NULL_TREE);
}

View File

@ -0,0 +1,19 @@
// PR c++/105758
struct A {
void foo(int);
};
template<class>
struct Z : A {
static Z *z;
void bar();
};
template<class T>
Z<T> *Z<T>::z;
template<class T>
void Z<T>::bar() {
z->foo(0);
}