From: Marek Polacek <polacek@redhat.com>
To: Jason Merrill <jason@redhat.com>, GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] c++: Disable -Wignored-qualifiers for template args [PR107492]
Date: Tue, 1 Nov 2022 13:01:56 -0400 [thread overview]
Message-ID: <20221101170156.52672-1-polacek@redhat.com> (raw)
It seems wrong to issue a -Wignored-qualifiers warning for code like:
static_assert(!is_same_v<void(*)(), const void(*)()>);
because there the qualifier matters. Likewise in template
specialization:
template<typename T> struct S { };
template<> struct S<void(*)()> { };
template<> struct S<const void(*)()> { }; // OK, not a redefinition
I'm of the mind that we should disable the warning for template
arguments, as in the patch below.
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
PR c++/107492
gcc/cp/ChangeLog:
* parser.cc (cp_parser_template_type_arg): Suppress -Wignored-qualifiers
warning.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wignored-qualifiers3.C: New test.
---
gcc/cp/parser.cc | 4 ++++
gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C | 12 ++++++++++++
2 files changed, 16 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index e0e3cf3eaf6..54ad4b98ed3 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -24334,6 +24334,10 @@ cp_parser_template_type_arg (cp_parser *parser)
const char *saved_message = parser->type_definition_forbidden_message;
parser->type_definition_forbidden_message
= G_("types may not be defined in template arguments");
+ /* It's wrong to issue a -Wignored-qualifiers warning for
+ static_assert(!is_same_v<void(*)(), const void(*)()>);
+ because there the qualifier matters. */
+ warning_sentinel w (warn_ignored_qualifiers);
r = cp_parser_type_id_1 (parser, CP_PARSER_FLAGS_NONE, true, false, NULL);
parser->type_definition_forbidden_message = saved_message;
if (cxx_dialect >= cxx14 && !flag_concepts && type_uses_auto (r))
diff --git a/gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C b/gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C
new file mode 100644
index 00000000000..5696feaaefe
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C
@@ -0,0 +1,12 @@
+// PR c++/107492
+// { dg-do compile { target c++14 } }
+// { dg-additional-options "-Wignored-qualifiers" }
+
+template<typename T> struct S { };
+template<> struct S<void(*)()> { };
+template<> struct S<const void(*)()> { }; // { dg-bogus "ignored" }
+
+template<typename T, typename U> constexpr bool is_same_v = false;
+template<typename T> constexpr bool is_same_v<T, T> = true;
+
+static_assert( ! is_same_v< void(*)(), const void(*)() >, ""); // { dg-bogus "ignored" }
base-commit: e7310e24b1c0ca67b1bb507c1330b2bf39e59e32
--
2.38.1
next reply other threads:[~2022-11-01 17:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-01 17:01 Marek Polacek [this message]
2022-11-03 19:22 ` Jason Merrill
2022-11-15 0:33 ` [PATCH v2] " Marek Polacek
2022-11-15 22:10 ` Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221101170156.52672-1-polacek@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).