Add more C2x attributes tests.
authorJoseph Myers <joseph@codesourcery.com>
Mon, 18 Nov 2019 17:41:40 +0000 (17:41 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Mon, 18 Nov 2019 17:41:40 +0000 (17:41 +0000)
This patch adds more tests of C2x attributes, where I found cases that
were handled correctly by my patches but missing from the original
tests.  Tests are added for -std=c11 -pedantic handling of C2x
attribute syntax and corresponding -Wc11-c2x-compat handling; for
struct [[deprecated]]; and for the [[__fallthrough__]] spelling of
[[fallthrough]] in the case of valid fallthrough attributes.

Tested for x86_64-pc-linux-gnu.

* gcc.dg/c11-attr-syntax-1.c, gcc.dg/c11-attr-syntax-2.c,
gcc.dg/c11-attr-syntax-3.c, gcc.dg/c2x-attr-syntax-4.c: New tests.
* gcc.dg/c2x-attr-deprecated-1.c: Also test struct [[deprecated]].
* gcc.dg/c2x-attr-fallthrough-1.c: Also test [[__fallthrough__]].

From-SVN: r278418

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c11-attr-syntax-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c11-attr-syntax-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c11-attr-syntax-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-attr-deprecated-1.c
gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c
gcc/testsuite/gcc.dg/c2x-attr-syntax-4.c [new file with mode: 0644]

index d8bd2fa3382597b7d8947a62fa46e84a8d6696c2..83f704f090659e6bb3ebc3d754132b14b5a67dc6 100644 (file)
@@ -1,3 +1,10 @@
+2019-11-18  Joseph Myers  <joseph@codesourcery.com>
+
+       * gcc.dg/c11-attr-syntax-1.c, gcc.dg/c11-attr-syntax-2.c,
+       gcc.dg/c11-attr-syntax-3.c, gcc.dg/c2x-attr-syntax-4.c: New tests.
+       * gcc.dg/c2x-attr-deprecated-1.c: Also test struct [[deprecated]].
+       * gcc.dg/c2x-attr-fallthrough-1.c: Also test [[__fallthrough__]].
+
 2019-11-18  Marek Polacek  <polacek@redhat.com>
 
        PR c++/91962 - ICE with reference binding and qualification conversion.
diff --git a/gcc/testsuite/gcc.dg/c11-attr-syntax-1.c b/gcc/testsuite/gcc.dg/c11-attr-syntax-1.c
new file mode 100644 (file)
index 0000000..5a3f70c
--- /dev/null
@@ -0,0 +1,7 @@
+/* Test C2x attribute syntax: rejected in C11.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+[[]]; /* { dg-error "attributes before C2X" } */
+
+void f [[]] (void); /* { dg-error "attributes before C2X" } */
diff --git a/gcc/testsuite/gcc.dg/c11-attr-syntax-2.c b/gcc/testsuite/gcc.dg/c11-attr-syntax-2.c
new file mode 100644 (file)
index 0000000..d92a189
--- /dev/null
@@ -0,0 +1,7 @@
+/* Test C2x attribute syntax: rejected in C11.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic" } */
+
+[[]]; /* { dg-warning "attributes before C2X" } */
+
+void f [[]] (void); /* { dg-warning "attributes before C2X" } */
diff --git a/gcc/testsuite/gcc.dg/c11-attr-syntax-3.c b/gcc/testsuite/gcc.dg/c11-attr-syntax-3.c
new file mode 100644 (file)
index 0000000..4d7cb77
--- /dev/null
@@ -0,0 +1,8 @@
+/* Test C2x attribute syntax: rejected in C11, but warning disabled
+   with -Wno-c11-c2x-compat.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic -Wno-c11-c2x-compat" } */
+
+[[]];
+
+void f [[]] (void);
index de0ae51c1443269cdf3152c6b441d3eb64fc1ef4..227c241bbd1fe5992b95abc355dd9565f46c1d9f 100644 (file)
@@ -89,3 +89,11 @@ f11 (void)
 {
   return y.b; /* { dg-warning "deprecated" } */
 }
+
+struct [[deprecated]] s { int x; };
+
+void
+f12 (void)
+{
+  struct s var; /* { dg-warning "deprecated" } */
+}
index ffa5226bf519a9d10477d275df4130094a2edad5..c0d9031cb9759f663d11d8a0ce4acee927ad3b11 100644 (file)
@@ -16,6 +16,12 @@ f (int a)
     case 3:
       b += 7;
       break;
+    case 4:
+      b = 5;
+      [[__fallthrough__]];
+    case 5:
+      b += 1;
+      break;
     }
   return b;
 }
diff --git a/gcc/testsuite/gcc.dg/c2x-attr-syntax-4.c b/gcc/testsuite/gcc.dg/c2x-attr-syntax-4.c
new file mode 100644 (file)
index 0000000..30c9668
--- /dev/null
@@ -0,0 +1,7 @@
+/* Test C2x attribute syntax: diagnosed with -Wc11-c2x-compat.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors -Wc11-c2x-compat" } */
+
+[[]]; /* { dg-warning "attributes before C2X" } */
+
+void f [[]] (void); /* { dg-warning "attributes before C2X" } */