* [PATCH] c++: bogus warning with value init of const pmf [PR92752]
@ 2022-01-28 17:54 Patrick Palka
2022-01-28 18:10 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2022-01-28 17:54 UTC (permalink / raw)
To: gcc-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: bogus warning with value init of const pmf [PR92752]
2022-01-28 17:54 [PATCH] c++: bogus warning with value init of const pmf [PR92752] Patrick Palka
@ 2022-01-28 18:10 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-01-28 18:10 UTC (permalink / raw)
To: Patrick Palka, gcc-patches
On 1/28/22 12:54, Patrick Palka wrote:
> 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);
Maybe we want to cast to TYPE_PTRMEMFUNC_FN_TYPE_RAW (to_type) instead
of "type" here? OK with that change.
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-28 18:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-28 17:54 [PATCH] c++: bogus warning with value init of const pmf [PR92752] Patrick Palka
2022-01-28 18:10 ` Jason Merrill
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).