From: Jakub Jelinek Date: Tue, 30 May 2017 08:24:21 +0000 (+0200) Subject: backport: re PR c++/80176 (cannot bind reference to static member function using... X-Git-Tag: releases/gcc-5.5.0~244 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c9109679c5f8f49e2970324f53f24f1568589f2;p=thirdparty%2Fgcc.git backport: re PR c++/80176 (cannot bind reference to static member function using object access expression) Backported from mainline 2017-04-10 Jakub Jelinek PR c++/80176 * tree.c (lvalue_kind): For COMPONENT_REF with BASELINK second operand, if it is a static member function, recurse on the BASELINK. * g++.dg/init/ref23.C: New test. From-SVN: r248669 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d867b9c5f9fa..1bd0d7cd4861 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,6 +1,13 @@ 2017-05-30 Jakub Jelinek Backported from mainline + 2017-04-10 Jakub Jelinek + + PR c++/80176 + * tree.c (lvalue_kind): For COMPONENT_REF with BASELINK second + operand, if it is a static member function, recurse on the + BASELINK. + 2017-03-22 Jakub Jelinek PR c++/80141 diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 4a7008b5a233..6b145c407594 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -129,6 +129,17 @@ lvalue_kind (const_tree ref) return op1_lvalue_kind; case COMPONENT_REF: + if (BASELINK_P (TREE_OPERAND (ref, 1))) + { + tree fn = BASELINK_FUNCTIONS (TREE_OPERAND (ref, 1)); + + /* For static member function recurse on the BASELINK, we can get + here e.g. from reference_binding. If BASELINK_FUNCTIONS is + OVERLOAD, the overload is resolved first if possible through + resolve_address_of_overloaded_function. */ + if (TREE_CODE (fn) == FUNCTION_DECL && DECL_STATIC_FUNCTION_P (fn)) + return lvalue_kind (TREE_OPERAND (ref, 1)); + } op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0)); /* Look at the member designator. */ if (!op1_lvalue_kind) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 771cf18547dc..d6179039f1a9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2017-05-30 Jakub Jelinek Backported from mainline + 2017-04-10 Jakub Jelinek + + PR c++/80176 + * g++.dg/init/ref23.C: New test. + 2017-04-04 Jakub Jelinek PR target/80286 diff --git a/gcc/testsuite/g++.dg/init/ref23.C b/gcc/testsuite/g++.dg/init/ref23.C new file mode 100644 index 000000000000..12b8851f2b96 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/ref23.C @@ -0,0 +1,15 @@ +// PR c++/80176 +// { dg-do compile } + +struct X { static void foo(); static void baz(int); static int baz(double); } x; +struct Y { void o(unsigned char); static void o(int); void o(double); } y; +void X::foo() {} +static void bar() {} +void (&r1)() = x.foo; +void (&r2)() = X::foo; +void (&r3)() = bar; +void (&r4)(int) = x.baz; +int (&r5)(double) = x.baz; +void (&r6)(int) = X::baz; +int (&r7)(double) = X::baz; +void (&r8)(int) = y.o;