[gcc r17-3396] c++: Fix propagating reference qualifier from function type to member function pointer type [PR70097

Jason Merrill via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:8f188b67517ce41561295506e3ba01ec1524854a

commit r17-3396-g8f188b67517ce41561295506e3ba01ec1524854a
Author: Eczbek <[email protected]>
Date:   Sun May 24 18:58:09 2026 -0400

    c++: Fix propagating reference qualifier from function type to member function pointer type [PR70097]
    
    When forming a member function pointer type to a ref-qualified function
    type, the reference qualifier is incorrectly dropped.
    
            PR c++/70097
    
    gcc/cp/ChangeLog:
    
            * decl.cc (grokdeclarator): If rqual is REF_QUAL_NONE, set it to
            result of type_memfn_rqual before passing to build_memfn_type.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/ref-qual22.C: New test.

Diff:
---
 gcc/cp/decl.cc                          |  2 ++
 gcc/testsuite/g++.dg/cpp0x/ref-qual22.C | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index cd533217ec40..bd9903c4e739 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -15805,6 +15805,8 @@ grokdeclarator (const cp_declarator *declarator,
 	      && TREE_CODE (type) == FUNCTION_TYPE)
 	    {
 	      memfn_quals |= type_memfn_quals (type);
+	      if (rqual == REF_QUAL_NONE)
+		rqual = type_memfn_rqual (type);
 	      type = build_memfn_type (type,
 				       declarator->u.pointer.class_type,
 				       memfn_quals,
diff --git a/gcc/testsuite/g++.dg/cpp0x/ref-qual22.C b/gcc/testsuite/g++.dg/cpp0x/ref-qual22.C
new file mode 100644
index 000000000000..4859d20053bf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/ref-qual22.C
@@ -0,0 +1,18 @@
+// PR c++/70097
+// { dg-do compile { target c++11 } }
+
+struct T {
+	void f() & {}
+	void g() && {}
+};
+using F = void() &;
+using G = void() &&;
+
+F T::* f = &T::f;
+G T::* g = &T::g;
+
+template<typename> struct U;
+template<> struct U<void(T::*)() &> {};
+template<> struct U<void(T::*)() &&> {};
+U<F T::*> u;
+U<G T::*> v;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.