Here we're emitting a -Wignored-qualifiers warning for an
intermediate compiler-generated cast of 0 to 'method-type* const'
as part of value initialization of a const pmf.  This patch
suppresses the warning by stripping cv-quals from this pointer
type before performing the cast.

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

        PR c++/92752

gcc/cp/ChangeLog:

        * typeck.cc (build_ptrmemfunc): Strip cv-quals from the pointer
        type after building the pmf type.

gcc/testsuite/ChangeLog:

        * g++.dg/warn/Wignored-qualifiers2.C: New test.
---
 gcc/cp/typeck.cc                                |  1 +
 .../g++.dg/warn/Wignored-qualifiers2.C          | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/warn/Wignored-qualifiers2.C

diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 11c9d8aff3e..0ce1cd3b6c8 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -9593,6 +9593,7 @@ build_ptrmemfunc (tree type, tree pfn, int force, bool 
c_cast_p,
   /* Handle null pointer to member function conversions.  */
   if (null_ptr_cst_p (pfn))
     {
+      type = cv_unqualified (type);
       pfn = cp_build_c_cast (input_location, type, pfn, complain);
       return build_ptrmemfunc1 (to_type,
                                integer_zero_node,
diff --git a/gcc/testsuite/g++.dg/warn/Wignored-qualifiers2.C 
b/gcc/testsuite/g++.dg/warn/Wignored-qualifiers2.C
new file mode 100644
index 00000000000..c4c37545c02
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wignored-qualifiers2.C
@@ -0,0 +1,17 @@
+// PR c++/92752
+// { dg-do compile }
+// { dg-additional-options "-Wignored-qualifiers" }
+
+struct X;
+
+template<class T>
+struct Wrap {
+  T data;
+  Wrap() : data() {}
+};
+
+typedef int (X::*type)();
+Wrap<const type> x;
+#if __cpp_initializer_lists
+const type t{};
+#endif
-- 
2.35.0

Reply via email to