From: Joseph Myers Date: Mon, 18 Nov 2019 17:41:40 +0000 (+0000) Subject: Add more C2x attributes tests. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=092508a07975a00b3bc7c4c6ef551d5b6dc2c193;p=gcc.git Add more C2x attributes tests. 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 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d8bd2fa3382..83f704f0906 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-11-18 Joseph Myers + + * 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 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 index 00000000000..5a3f70cd71f --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-attr-syntax-1.c @@ -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 index 00000000000..d92a1891abb --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-attr-syntax-2.c @@ -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 index 00000000000..4d7cb77d09a --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-attr-syntax-3.c @@ -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); diff --git a/gcc/testsuite/gcc.dg/c2x-attr-deprecated-1.c b/gcc/testsuite/gcc.dg/c2x-attr-deprecated-1.c index de0ae51c144..227c241bbd1 100644 --- a/gcc/testsuite/gcc.dg/c2x-attr-deprecated-1.c +++ b/gcc/testsuite/gcc.dg/c2x-attr-deprecated-1.c @@ -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" } */ +} diff --git a/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c b/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c index ffa5226bf51..c0d9031cb97 100644 --- a/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c +++ b/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c @@ -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 index 00000000000..30c966817be --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-attr-syntax-4.c @@ -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" } */