public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: non-dep call with empty TYPE_BINFO [PR105758]
@ 2022-05-31 16:28 Patrick Palka
  2022-05-31 19:04 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2022-05-31 16:28 UTC (permalink / raw)
  To: gcc-patches

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

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_1, 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 kinds 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.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/12?

	PR c++/105758

gcc/cp/ChangeLog:

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

gcc/testsuite/ChangeLog:

	* g++.dg/template/non-dependent24.C: New test.
---
 gcc/cp/call.cc                                |  4 ++--
 .../g++.dg/template/non-dependent24.C         | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/non-dependent24.C

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 14c6037729f..85fe9b5ab85 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -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);
 	}
diff --git a/gcc/testsuite/g++.dg/template/non-dependent24.C b/gcc/testsuite/g++.dg/template/non-dependent24.C
new file mode 100644
index 00000000000..0ddc75c78ee
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/non-dependent24.C
@@ -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);
+}
-- 
2.36.1.203.g1bcf4f6271


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: non-dep call with empty TYPE_BINFO [PR105758]
  2022-05-31 16:28 [PATCH] c++: non-dep call with empty TYPE_BINFO [PR105758] Patrick Palka
@ 2022-05-31 19:04 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-05-31 19:04 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 5/31/22 12:28, Patrick Palka wrote:
> Here the out-of-line definition of Z<T>::z causes duplicate_decls to
> change z's type to use the implicit instantiation Z<T> rather than the
> corresponding primary template type (which is also the type of the
> injected class name), and the former, being a dependent specialization,
> lacks a TYPE_BINFO (although its TYPE_CANONICAL was set by a special
> case in lookup_template_class_1 to point to the latter).
> 
> 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_1, 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 kinds 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.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/12?

OK.

> 	PR c++/105758
> 
> gcc/cp/ChangeLog:
> 
> 	* call.cc (build_over_call): Use z_candidate::conversion_path
> 	and ::access_path instead of TYPE_BINFO to build the BASELINK
> 	for the templated form.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/template/non-dependent24.C: New test.
> ---
>   gcc/cp/call.cc                                |  4 ++--
>   .../g++.dg/template/non-dependent24.C         | 19 +++++++++++++++++++
>   2 files changed, 21 insertions(+), 2 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/template/non-dependent24.C
> 
> diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
> index 14c6037729f..85fe9b5ab85 100644
> --- a/gcc/cp/call.cc
> +++ b/gcc/cp/call.cc
> @@ -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);
>   	}
> diff --git a/gcc/testsuite/g++.dg/template/non-dependent24.C b/gcc/testsuite/g++.dg/template/non-dependent24.C
> new file mode 100644
> index 00000000000..0ddc75c78ee
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/non-dependent24.C
> @@ -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);
> +}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-31 19:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 16:28 [PATCH] c++: non-dep call with empty TYPE_BINFO [PR105758] Patrick Palka
2022-05-31 19:04 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).