From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Cc: "Joseph S. Myers" <joseph@codesourcery.com>
Subject: c-warn PATCH to silence warnings about std::byte in switch
Date: Fri, 19 May 2017 19:39:00 -0000 [thread overview]
Message-ID: <CADzB+2k20qis8C0j=rVSB1d73opZz-98CE_JMcz3n3waS--qxA@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 397 bytes --]
It doesn't make sense to warn about a switch case not being an
enumerator if the enum type has no enumerators; such a type is being
used as an opaque typedef rather than a true enumerated type. This
usage makes more sense with C++11 enums with explicitly specified
underlying type, but I don't think it's necessary to limit the patch
to that case.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: byte-case.diff --]
[-- Type: text/plain, Size: 1216 bytes --]
commit 673265c3d4cd77c7b0e927cc1547444ef869ad3a
Author: Jason Merrill <jason@redhat.com>
Date: Thu May 18 22:45:24 2017 -0400
* c-warn.c (match_case_to_enum_1): Don't warn about enums with no
enumerators.
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index e67ffb7..8971156 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -1069,6 +1069,10 @@ warnings_for_convert_and_check (location_t loc, tree type, tree expr,
static void
match_case_to_enum_1 (tree key, tree type, tree label)
{
+ /* Avoid warning about enums that have no enumerators. */
+ if (TYPE_VALUES (type) == NULL_TREE)
+ return;
+
char buf[WIDE_INT_PRINT_BUFFER_SIZE];
if (tree_fits_uhwi_p (key))
diff --git a/gcc/testsuite/g++.dg/cpp1z/byte2.C b/gcc/testsuite/g++.dg/cpp1z/byte2.C
new file mode 100644
index 0000000..6a395c1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/byte2.C
@@ -0,0 +1,13 @@
+// { dg-options "-std=c++17 -Wall" }
+
+#include <cstddef>
+
+bool white_space(std::byte x) {
+ switch (x) {
+ case std::byte{' '}: case std::byte{'\t'}: case std::byte{'\v'}:
+ case std::byte{'\f'}: case std::byte{'\n'}:
+ return true;
+ default:
+ return false;
+ }
+}
reply other threads:[~2017-05-19 19:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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='CADzB+2k20qis8C0j=rVSB1d73opZz-98CE_JMcz3n3waS--qxA@mail.gmail.com' \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=joseph@codesourcery.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).