public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-11483] c++: bogus warning with value init of const pmf [PR92752]
@ 2023-06-30  4:04 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2023-06-30  4:04 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8c12c47d0c5c40df6e5eeb8625d4708c8a42dbe0

commit r10-11483-g8c12c47d0c5c40df6e5eeb8625d4708c8a42dbe0
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Jan 28 15:41:15 2022 -0500

    c++: bogus warning with value init of const pmf [PR92752]
    
    Here we're emitting a -Wignored-qualifiers warning for an intermediate
    compiler-generated cast of nullptr to 'method-type* const' as part of
    value initialization of a const pmf.  This patch suppresses the warning
    by instead casting to the corresponding unqualified type.
    
            PR c++/92752
    
    gcc/cp/ChangeLog:
    
            * typeck.c (build_ptrmemfunc): Cast a nullptr constant to the
            unqualified pointer type not the qualified one.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/warn/Wignored-qualifiers2.C: New test.
    
    Co-authored-by: Jason Merrill <jason@redhat.com>
    (cherry picked from commit e971990cbda091b4caf5e1a5bded5121068934e4)

Diff:
---
 gcc/cp/typeck.c                                  |  4 +++-
 gcc/testsuite/g++.dg/warn/Wignored-qualifiers2.C | 17 +++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 548c81ef12c..b23f03a032b 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -9092,7 +9092,9 @@ 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))
     {
-      pfn = cp_build_c_cast (input_location, type, pfn, complain);
+      pfn = cp_build_c_cast (input_location,
+			     TYPE_PTRMEMFUNC_FN_TYPE_RAW (to_type),
+			     pfn, complain);
       return build_ptrmemfunc1 (to_type,
 				integer_zero_node,
 				pfn);
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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-30  4:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-30  4:04 [gcc r10-11483] c++: bogus warning with value init of const pmf [PR92752] Patrick Palka

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).