aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2022-08-18 23:01:01 +0000
committerJoseph Myers <joseph@codesourcery.com>2022-08-18 23:01:01 +0000
commitd7c3000147c1d8090f66a2baf4623d2c0dfe8eb6 (patch)
treebd7d06ce9c89f25ee43e73644ed143f5947147a7 /gcc
parent8731aa98674eda56425ffd652918ce4979631f67 (diff)
downloadgcc-d7c3000147c1d8090f66a2baf4623d2c0dfe8eb6.zip
gcc-d7c3000147c1d8090f66a2baf4623d2c0dfe8eb6.tar.gz
gcc-d7c3000147c1d8090f66a2baf4623d2c0dfe8eb6.tar.bz2
preprocessor: Support #warning for standard C2x
ISO C2x standardizes the existing #warning extension. Arrange accordingly for it not to be diagnosed with -std=c2x -pedantic, but to be diagnosed with -Wc11-c2x-compat. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/testsuite/ * gcc.dg/cpp/c11-warning-1.c, gcc.dg/cpp/c11-warning-2.c, gcc.dg/cpp/c11-warning-3.c, gcc.dg/cpp/c11-warning-4.c, gcc.dg/cpp/c2x-warning-1.c, gcc.dg/cpp/c2x-warning-2.c, gcc.dg/cpp/gnu11-warning-1.c, gcc.dg/cpp/gnu11-warning-2.c, gcc.dg/cpp/gnu11-warning-3.c, gcc.dg/cpp/gnu11-warning-4.c, gcc.dg/cpp/gnu2x-warning-1.c, gcc.dg/cpp/gnu2x-warning-2.c: New tests. libcpp/ * include/cpplib.h (struct cpp_options): Add warning_directive. * init.cc (struct lang_flags, lang_defaults): Add warning_directive. * directives.cc (DIRECTIVE_TABLE): Mark #warning as STDC2X not EXTENSION. (directive_diagnostics): Diagnose #warning with -Wc11-c2x-compat, or with -pedantic for a standard not supporting #warning.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.dg/cpp/c11-warning-1.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/c11-warning-2.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/c11-warning-3.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/c11-warning-4.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/c2x-warning-1.c5
-rw-r--r--gcc/testsuite/gcc.dg/cpp/c2x-warning-2.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/gnu11-warning-1.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/gnu11-warning-2.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/gnu11-warning-3.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/gnu11-warning-4.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/gnu2x-warning-1.c5
-rw-r--r--gcc/testsuite/gcc.dg/cpp/gnu2x-warning-2.c6
12 files changed, 70 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/cpp/c11-warning-1.c b/gcc/testsuite/gcc.dg/cpp/c11-warning-1.c
new file mode 100644
index 0000000..45d1ff8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/c11-warning-1.c
@@ -0,0 +1,6 @@
+/* Test #warning not in C11. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+#warning example text /* { dg-warning "example text" } */
+/* { dg-error "#warning before C2X is a GCC extension" "pedantic" { target *-*-* } .-1 } */
diff --git a/gcc/testsuite/gcc.dg/cpp/c11-warning-2.c b/gcc/testsuite/gcc.dg/cpp/c11-warning-2.c
new file mode 100644
index 0000000..ba385bf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/c11-warning-2.c
@@ -0,0 +1,6 @@
+/* Test #warning not in C11. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c11 -pedantic" } */
+
+#warning example text /* { dg-warning "example text" } */
+/* { dg-warning "#warning before C2X is a GCC extension" "pedantic" { target *-*-* } .-1 } */
diff --git a/gcc/testsuite/gcc.dg/cpp/c11-warning-3.c b/gcc/testsuite/gcc.dg/cpp/c11-warning-3.c
new file mode 100644
index 0000000..8d74fcd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/c11-warning-3.c
@@ -0,0 +1,6 @@
+/* Test #warning not in C11. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c11 -Wc11-c2x-compat" } */
+
+#warning example text /* { dg-warning "example text" } */
+/* { dg-warning "#warning before C2X is a GCC extension" "compat" { target *-*-* } .-1 } */
diff --git a/gcc/testsuite/gcc.dg/cpp/c11-warning-4.c b/gcc/testsuite/gcc.dg/cpp/c11-warning-4.c
new file mode 100644
index 0000000..0af93f3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/c11-warning-4.c
@@ -0,0 +1,6 @@
+/* Test #warning not in C11. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c11" } */
+
+#warning example text /* { dg-warning "example text" } */
+/* Not diagnosed by default. */
diff --git a/gcc/testsuite/gcc.dg/cpp/c2x-warning-1.c b/gcc/testsuite/gcc.dg/cpp/c2x-warning-1.c
new file mode 100644
index 0000000..696a0cd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/c2x-warning-1.c
@@ -0,0 +1,5 @@
+/* Test #warning in C2x. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+
+#warning example text /* { dg-warning "example text" } */
diff --git a/gcc/testsuite/gcc.dg/cpp/c2x-warning-2.c b/gcc/testsuite/gcc.dg/cpp/c2x-warning-2.c
new file mode 100644
index 0000000..3042e7a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/c2x-warning-2.c
@@ -0,0 +1,6 @@
+/* Test #warning in C2x: -Wc11-c2x-comapt. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c2x -pedantic-errors -Wc11-c2x-compat" } */
+
+#warning example text /* { dg-warning "example text" } */
+/* { dg-warning "#warning before C2X is a GCC extension" "compat" { target *-*-* } .-1 } */
diff --git a/gcc/testsuite/gcc.dg/cpp/gnu11-warning-1.c b/gcc/testsuite/gcc.dg/cpp/gnu11-warning-1.c
new file mode 100644
index 0000000..7dda115
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/gnu11-warning-1.c
@@ -0,0 +1,6 @@
+/* Test #warning not in C11. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=gnu11 -pedantic-errors" } */
+
+#warning example text /* { dg-warning "example text" } */
+/* { dg-error "#warning before C2X is a GCC extension" "pedantic" { target *-*-* } .-1 } */
diff --git a/gcc/testsuite/gcc.dg/cpp/gnu11-warning-2.c b/gcc/testsuite/gcc.dg/cpp/gnu11-warning-2.c
new file mode 100644
index 0000000..af2cc34
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/gnu11-warning-2.c
@@ -0,0 +1,6 @@
+/* Test #warning not in C11. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=gnu11 -pedantic" } */
+
+#warning example text /* { dg-warning "example text" } */
+/* { dg-warning "#warning before C2X is a GCC extension" "pedantic" { target *-*-* } .-1 } */
diff --git a/gcc/testsuite/gcc.dg/cpp/gnu11-warning-3.c b/gcc/testsuite/gcc.dg/cpp/gnu11-warning-3.c
new file mode 100644
index 0000000..22b7b50
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/gnu11-warning-3.c
@@ -0,0 +1,6 @@
+/* Test #warning not in C11. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=gnu11 -Wc11-c2x-compat" } */
+
+#warning example text /* { dg-warning "example text" } */
+/* { dg-warning "#warning before C2X is a GCC extension" "compat" { target *-*-* } .-1 } */
diff --git a/gcc/testsuite/gcc.dg/cpp/gnu11-warning-4.c b/gcc/testsuite/gcc.dg/cpp/gnu11-warning-4.c
new file mode 100644
index 0000000..fd8ecfb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/gnu11-warning-4.c
@@ -0,0 +1,6 @@
+/* Test #warning not in C11. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=gnu11" } */
+
+#warning example text /* { dg-warning "example text" } */
+/* Not diagnosed by default. */
diff --git a/gcc/testsuite/gcc.dg/cpp/gnu2x-warning-1.c b/gcc/testsuite/gcc.dg/cpp/gnu2x-warning-1.c
new file mode 100644
index 0000000..c8e5290
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/gnu2x-warning-1.c
@@ -0,0 +1,5 @@
+/* Test #warning in C2x. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=gnu2x -pedantic-errors" } */
+
+#warning example text /* { dg-warning "example text" } */
diff --git a/gcc/testsuite/gcc.dg/cpp/gnu2x-warning-2.c b/gcc/testsuite/gcc.dg/cpp/gnu2x-warning-2.c
new file mode 100644
index 0000000..3aef4b3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/gnu2x-warning-2.c
@@ -0,0 +1,6 @@
+/* Test #warning in C2x: -Wc11-c2x-comapt. */
+/* { dg-do preprocess } */
+/* { dg-options "-std=gnu2x -pedantic-errors -Wc11-c2x-compat" } */
+
+#warning example text /* { dg-warning "example text" } */
+/* { dg-warning "#warning before C2X is a GCC extension" "compat" { target *-*-* } .-1 } */