public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR c++/109958: ICE taking the address of bound static member function brought into derived class by using-declaration
       [not found] <20240531135800.79284-1-simon@nasilyan.com>
@ 2024-05-31 13:58 ` Simon Martin
  2024-05-31 20:30   ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Martin @ 2024-05-31 13:58 UTC (permalink / raw)
  To: gcc-patches

From: Simon Martin <simon@nasilyan.com>

We currently ICE upon the following because we don't properly handle the
overload created for B::f through the using statement.

=== cut here ===
struct B { static int f(); };
struct D : B { using B::f; };
void f(D d) { &d.f; }
=== cut here ===

This patch makes build_class_member_access_expr and cp_build_addr_expr_1 handle
such overloads, and fixes the PR.

Successfully tested on x86_64-pc-linux-gnu.

	PR c++/109958

gcc/cp/ChangeLog:

	* typeck.cc (build_class_member_access_expr): Handle single OVERLOADs.
	(cp_build_addr_expr_1): Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/overload/using6.C: New test.

---
 gcc/cp/typeck.cc                       | 5 +++++
 gcc/testsuite/g++.dg/overload/using6.C | 5 +++++
 2 files changed, 10 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/overload/using6.C

diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 1b7a31d32f3..5970ac3d398 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -3025,6 +3025,8 @@ build_class_member_access_expr (cp_expr object, tree member,
 	 know the type of the expression.  Otherwise, we must wait
 	 until overload resolution has been performed.  */
       functions = BASELINK_FUNCTIONS (member);
+      if (TREE_CODE (functions) == OVERLOAD && OVL_SINGLE_P (functions))
+	functions = OVL_FIRST (functions);
       if (TREE_CODE (functions) == FUNCTION_DECL
 	  && DECL_STATIC_FUNCTION_P (functions))
 	type = TREE_TYPE (functions);
@@ -7333,6 +7335,9 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
     {
       tree fn = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1));
 
+      if (TREE_CODE (fn) == OVERLOAD && OVL_SINGLE_P (fn))
+	fn = OVL_FIRST (fn);
+
       /* We can only get here with a single static member
 	 function.  */
       gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
diff --git a/gcc/testsuite/g++.dg/overload/using6.C b/gcc/testsuite/g++.dg/overload/using6.C
new file mode 100644
index 00000000000..4f89f68a30f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/overload/using6.C
@@ -0,0 +1,5 @@
+// PR c++/109958
+
+struct B { static int f(); };
+struct D : B { using B::f; };
+void f(D d) { &d.f; }
-- 
2.44.0



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

* Re: [PATCH] Fix PR c++/109958: ICE taking the address of bound static member function brought into derived class by using-declaration
  2024-05-31 13:58 ` [PATCH] Fix PR c++/109958: ICE taking the address of bound static member function brought into derived class by using-declaration Simon Martin
@ 2024-05-31 20:30   ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-05-31 20:30 UTC (permalink / raw)
  To: Simon Martin, gcc-patches

On 5/31/24 09:58, Simon Martin wrote:
> From: Simon Martin <simon@nasilyan.com>
> 
> We currently ICE upon the following because we don't properly handle the
> overload created for B::f through the using statement.
> 
> === cut here ===
> struct B { static int f(); };
> struct D : B { using B::f; };
> void f(D d) { &d.f; }
> === cut here ===
> 
> This patch makes build_class_member_access_expr and cp_build_addr_expr_1 handle
> such overloads, and fixes the PR.
> 
> Successfully tested on x86_64-pc-linux-gnu.
> 
> 	PR c++/109958
> 
> gcc/cp/ChangeLog:
> 
> 	* typeck.cc (build_class_member_access_expr): Handle single OVERLOADs.
> 	(cp_build_addr_expr_1): Likewise.

OK.

> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/overload/using6.C: New test.
> 
> ---
>   gcc/cp/typeck.cc                       | 5 +++++
>   gcc/testsuite/g++.dg/overload/using6.C | 5 +++++
>   2 files changed, 10 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/overload/using6.C
> 
> diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
> index 1b7a31d32f3..5970ac3d398 100644
> --- a/gcc/cp/typeck.cc
> +++ b/gcc/cp/typeck.cc
> @@ -3025,6 +3025,8 @@ build_class_member_access_expr (cp_expr object, tree member,
>   	 know the type of the expression.  Otherwise, we must wait
>   	 until overload resolution has been performed.  */
>         functions = BASELINK_FUNCTIONS (member);
> +      if (TREE_CODE (functions) == OVERLOAD && OVL_SINGLE_P (functions))
> +	functions = OVL_FIRST (functions);
>         if (TREE_CODE (functions) == FUNCTION_DECL
>   	  && DECL_STATIC_FUNCTION_P (functions))
>   	type = TREE_TYPE (functions);
> @@ -7333,6 +7335,9 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
>       {
>         tree fn = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1));
>   
> +      if (TREE_CODE (fn) == OVERLOAD && OVL_SINGLE_P (fn))
> +	fn = OVL_FIRST (fn);
> +
>         /* We can only get here with a single static member
>   	 function.  */
>         gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
> diff --git a/gcc/testsuite/g++.dg/overload/using6.C b/gcc/testsuite/g++.dg/overload/using6.C
> new file mode 100644
> index 00000000000..4f89f68a30f
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/overload/using6.C
> @@ -0,0 +1,5 @@
> +// PR c++/109958
> +
> +struct B { static int f(); };
> +struct D : B { using B::f; };
> +void f(D d) { &d.f; }


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

end of thread, other threads:[~2024-05-31 20:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20240531135800.79284-1-simon@nasilyan.com>
2024-05-31 13:58 ` [PATCH] Fix PR c++/109958: ICE taking the address of bound static member function brought into derived class by using-declaration Simon Martin
2024-05-31 20:30   ` 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).