From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [C++ PATCH] Fix -Wimplicit-fallthrough in templates (PR c++/77886)
Date: Sat, 08 Oct 2016 06:15:00 -0000 [thread overview]
Message-ID: <20161008061350.GL7282@tucnak.redhat.com> (raw)
Hi!
As the testcase shows, we weren't copying over FALLTHROUGH_LABEL_P during
instantiations, which means that // FALLTHROUGH comments in templates were
ignored (while [[fallthrough]];, being represented as internal calls,
worked fine).
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?
2016-10-08 Jakub Jelinek <jakub@redhat.com>
PR c++/77886
* pt.c (tsubst_expr) <case CASE_LABEL_EXPR> Copy over
FALLTHROUGH_LABEL_P flag to the new LABEL_DECL.
(tsubst_expr) <case LABEL_EXPR>: Likewise.
* g++.dg/warn/Wimplicit-fallthrough-2.C: New test.
--- gcc/cp/pt.c.jj 2016-10-07 21:36:47.000000000 +0200
+++ gcc/cp/pt.c 2016-10-07 23:51:53.244510627 +0200
@@ -15456,7 +15456,10 @@ tsubst_expr (tree t, tree args, tsubst_f
{
tree low = RECUR (CASE_LOW (t));
tree high = RECUR (CASE_HIGH (t));
- finish_case_label (EXPR_LOCATION (t), low, high);
+ tree l = finish_case_label (EXPR_LOCATION (t), low, high);
+ if (l && TREE_CODE (l) == CASE_LABEL_EXPR)
+ FALLTHROUGH_LABEL_P (CASE_LABEL (l))
+ = FALLTHROUGH_LABEL_P (CASE_LABEL (t));
}
break;
@@ -15466,6 +15469,8 @@ tsubst_expr (tree t, tree args, tsubst_f
tree label;
label = finish_label_stmt (DECL_NAME (decl));
+ if (TREE_CODE (label) == LABEL_DECL)
+ FALLTHROUGH_LABEL_P (label) = FALLTHROUGH_LABEL_P (decl);
if (DECL_ATTRIBUTES (decl) != NULL_TREE)
cplus_decl_attributes (&label, DECL_ATTRIBUTES (decl), 0);
}
--- gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-2.C.jj 2016-10-07 23:59:03.851102742 +0200
+++ gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-2.C 2016-10-08 00:04:25.759058055 +0200
@@ -0,0 +1,66 @@
+// PR c++/77886
+// { dg-do compile }
+// { dg-options "-Wimplicit-fallthrough" }
+
+template <int N>
+int
+foo (int x, int y)
+{
+ switch (x)
+ {
+ case 1:
+ x++; // { dg-bogus "this statement may f\[ahlotu\]*gh" }
+ // FALLTHROUGH
+ case 2:
+ x++;
+ break;
+ case 3:
+ x++; // { dg-bogus "this statement may f\[ahlotu\]*gh" }
+ // FALLTHROUGH
+ lab:
+ case 4:
+ x++;
+ break;
+ case 5:
+ x++; // { dg-bogus "this statement may f\[ahlotu\]*gh" }
+ // FALLTHROUGH
+ default:
+ x++;
+ break;
+ case 26:
+ goto lab;
+ }
+#if __cplusplus >= 201103L
+ switch (y)
+ {
+ case 1:
+ y++; // { dg-bogus "this statement may f\[ahlotu\]*gh" }
+ [[fallthrough]];
+ case 2:
+ y++;
+ break;
+ case 3:
+ y++; // { dg-bogus "this statement may f\[ahlotu\]*gh" }
+ [[fallthrough]];
+ lab2:
+ case 4:
+ y++;
+ break;
+ case 5:
+ y++; // { dg-bogus "this statement may f\[ahlotu\]*gh" }
+ [[fallthrough]];
+ default:
+ y++;
+ break;
+ case 26:
+ goto lab2;
+ }
+#endif
+ return x + y;
+}
+
+int
+bar (int x, int y)
+{
+ return foo<0> (x, y);
+}
Jakub
next reply other threads:[~2016-10-08 6:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-08 6:15 Jakub Jelinek [this message]
2016-10-17 17:37 ` Patch ping Jakub Jelinek
2016-10-31 13:33 ` [C++ PATCH] Fix -Wimplicit-fallthrough in templates (PR c++/77886) 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=20161008061350.GL7282@tucnak.redhat.com \
--to=jakub@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).