summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2022-01-28 15:41:15 -0500
committerPatrick Palka <ppalka@redhat.com>2023-06-30 00:03:15 -0400
commit8c12c47d0c5c40df6e5eeb8625d4708c8a42dbe0 (patch)
tree28292b4535dcd1e7deddbbeadd3122f240265b67
parentad42219766d0e67bede2c9bd94c98082cde42518 (diff)
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)
-rw-r--r--gcc/cp/typeck.c4
-rw-r--r--gcc/testsuite/g++.dg/warn/Wignored-qualifiers2.C17
2 files changed, 20 insertions, 1 deletions
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