summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/attr-fallthrough-1.c
diff options
context:
space:
mode:
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>2016-09-26 09:42:50 +0000
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>2016-09-26 09:42:50 +0000
commit3c77f69c50d3377491c917808fbfc4b9787acd6f (patch)
tree8b84b3de175727d09b7dcf1b5703e0d46b64f9e7 /gcc/testsuite/c-c++-common/attr-fallthrough-1.c
parenta8d09781ee8c8e0020fac0fbdb15669710fea4b4 (diff)
downloadgcc-3c77f69c50d3377491c917808fbfc4b9787acd6f.tar.gz
Implement -Wimplicit-fallthrough.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@240485 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/c-c++-common/attr-fallthrough-1.c')
-rw-r--r--gcc/testsuite/c-c++-common/attr-fallthrough-1.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/attr-fallthrough-1.c b/gcc/testsuite/c-c++-common/attr-fallthrough-1.c
new file mode 100644
index 00000000000..ecfd094d9cd
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/attr-fallthrough-1.c
@@ -0,0 +1,57 @@
+/* PR c/7652 */
+/* { dg-do compile } */
+/* { dg-options "-Wall -Wextra -Wpedantic" } */
+
+extern void bar (int);
+void
+fn (int i)
+{
+ __attribute__((fallthrough)) int j = 0; /* { dg-warning "ignored|attribute not followed" } */
+
+ if (j)
+ __attribute__((fallthrough)); /* { dg-error "invalid use" } */
+
+ __attribute__((fallthrough)); /* { dg-error "invalid use" } */
+ switch (i)
+ {
+ __attribute__((fallthrough)); /* { dg-warning "statement will never" } */
+ case 1:
+ i++;
+ __attribute__((fallthrough));
+ case 2:
+ if (i) /* { dg-warning "statement may fall through" } */
+ bar (2);
+ else
+ __attribute__((fallthrough));
+ case 3:
+ if (i > 1)
+ __attribute__((fallthrough));
+ else
+ return;
+ case 4:
+ if (i)
+ __attribute__((fallthrough)); /* { dg-warning "not preceding" } */
+ __attribute__((fallthrough));
+ case 5:
+ ;
+ __attribute__((fallthrough));
+ case 6:
+ if (i) /* { dg-warning "statement may fall through" } */
+ bar (6);
+ else
+ {
+ __attribute__((fallthrough));
+ }
+ case 7:
+ if (i > 1)
+ {
+ __attribute__((fallthrough));
+ }
+ else
+ bar (7); /* { dg-warning "statement may fall through" } */
+ default:
+ --j;
+ }
+
+ __attribute__((fallthrough)); /* { dg-error "invalid use" } */
+}