* [committed] preprocessor: Support #warning for standard C2x
@ 2022-08-18 23:02 Joseph Myers
2022-08-22 9:53 ` [PATCH] preprocessor: Implement C++23 P2437R1 - Support for #warning [PR106646] Jakub Jelinek
0 siblings, 1 reply; 3+ messages in thread
From: Joseph Myers @ 2022-08-18 23:02 UTC (permalink / raw)
To: gcc-patches
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.
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 00000000000..45d1ff874e9
--- /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 00000000000..ba385bf60fb
--- /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 00000000000..8d74fcdaea4
--- /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 00000000000..0af93f3f459
--- /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 00000000000..696a0cd7aad
--- /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 00000000000..3042e7a088c
--- /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 00000000000..7dda115ab3e
--- /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 00000000000..af2cc349702
--- /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 00000000000..22b7b50e108
--- /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 00000000000..fd8ecfbef6e
--- /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 00000000000..c8e5290f280
--- /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 00000000000..3aef4b328fc
--- /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 } */
diff --git a/libcpp/directives.cc b/libcpp/directives.cc
index 4104d5166e2..802bd8c8bb5 100644
--- a/libcpp/directives.cc
+++ b/libcpp/directives.cc
@@ -158,7 +158,7 @@ static void cpp_pop_definition (cpp_reader *, struct def_pragma_macro *);
D(elifndef, T_ELIFNDEF, STDC2X, COND | ELIFDEF) \
D(error, T_ERROR, STDC89, 0) \
D(pragma, T_PRAGMA, STDC89, IN_I) \
- D(warning, T_WARNING, EXTENSION, 0) \
+ D(warning, T_WARNING, STDC2X, 0) \
D(include_next, T_INCLUDE_NEXT, EXTENSION, INCL | EXPAND) \
D(ident, T_IDENT, EXTENSION, IN_I) \
D(import, T_IMPORT, EXTENSION, INCL | EXPAND) /* ObjC */ \
@@ -385,6 +385,15 @@ directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented)
&& !(dir == &dtable[T_IMPORT] && CPP_OPTION (pfile, objc))
&& CPP_PEDANTIC (pfile))
cpp_error (pfile, CPP_DL_PEDWARN, "#%s is a GCC extension", dir->name);
+ else if (dir == &dtable[T_WARNING])
+ {
+ if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, warning_directive))
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "#%s before C2X is a GCC extension", dir->name);
+ else if (CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) > 0)
+ cpp_warning (pfile, CPP_W_C11_C2X_COMPAT,
+ "#%s before C2X is a GCC extension", dir->name);
+ }
else if (((dir->flags & DEPRECATED) != 0
|| (dir == &dtable[T_IMPORT] && !CPP_OPTION (pfile, objc)))
&& CPP_OPTION (pfile, cpp_warn_deprecated))
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 26e2b4cf472..58ed51d845c 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -513,6 +513,9 @@ struct cpp_options
/* Nonzero for the '#elifdef' and '#elifndef' directives. */
unsigned char elifdef;
+ /* Nonzero for the '#warning' directive. */
+ unsigned char warning_directive;
+
/* Nonzero means tokenize C++20 module directives. */
unsigned char module_directives;
diff --git a/libcpp/init.cc b/libcpp/init.cc
index 59641a7f876..8d99bdb1b8d 100644
--- a/libcpp/init.cc
+++ b/libcpp/init.cc
@@ -96,34 +96,35 @@ struct lang_flags
char dfp_constants;
char size_t_literals;
char elifdef;
+ char warning_directive;
};
static const struct lang_flags lang_defaults[] =
-{ /* c99 c++ xnum xid c11 std digr ulit rlit udlit bincst digsep trig u8chlit vaopt scope dfp szlit elifdef */
- /* GNUC89 */ { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
- /* GNUC99 */ { 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
- /* GNUC11 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
- /* GNUC17 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
- /* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1 },
- /* STDC89 */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
- /* STDC94 */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
- /* STDC99 */ { 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
- /* STDC11 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
- /* STDC17 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
- /* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1 },
- /* GNUCXX */ { 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
- /* CXX98 */ { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0 },
- /* GNUCXX11 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
- /* CXX11 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0 },
- /* GNUCXX14 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 },
- /* CXX14 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0 },
- /* GNUCXX17 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0 },
- /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0 },
- /* GNUCXX20 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0 },
- /* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0 },
- /* GNUCXX23 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1 },
- /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1 },
- /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+{ /* c99 c++ xnum xid c11 std digr ulit rlit udlit bincst digsep trig u8chlit vaopt scope dfp szlit elifdef warndir */
+ /* GNUC89 */ { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
+ /* GNUC99 */ { 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
+ /* GNUC11 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
+ /* GNUC17 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
+ /* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1 },
+ /* STDC89 */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
+ /* STDC94 */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
+ /* STDC99 */ { 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
+ /* STDC11 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
+ /* STDC17 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
+ /* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1 },
+ /* GNUCXX */ { 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
+ /* CXX98 */ { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0 },
+ /* GNUCXX11 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
+ /* CXX11 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0 },
+ /* GNUCXX14 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0 },
+ /* CXX14 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0 },
+ /* GNUCXX17 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0 },
+ /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0 },
+ /* GNUCXX20 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0 },
+ /* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0 },
+ /* GNUCXX23 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0 },
+ /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0 },
+ /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
/* Sets internal flags correctly for a given language. */
@@ -153,6 +154,7 @@ cpp_set_lang (cpp_reader *pfile, enum c_lang lang)
CPP_OPTION (pfile, dfp_constants) = l->dfp_constants;
CPP_OPTION (pfile, size_t_literals) = l->size_t_literals;
CPP_OPTION (pfile, elifdef) = l->elifdef;
+ CPP_OPTION (pfile, warning_directive) = l->warning_directive;
}
/* Initialize library global state. */
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] preprocessor: Implement C++23 P2437R1 - Support for #warning [PR106646]
2022-08-18 23:02 [committed] preprocessor: Support #warning for standard C2x Joseph Myers
@ 2022-08-22 9:53 ` Jakub Jelinek
2022-08-23 21:54 ` Jason Merrill
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2022-08-22 9:53 UTC (permalink / raw)
To: Jason Merrill, Joseph Myers; +Cc: gcc-patches, Marek Polacek
Hi!
On Thu, Aug 18, 2022 at 11:02:44PM +0000, Joseph Myers wrote:
> 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.
And here is the corresponding C++ version.
Don't pedwarn about this for C++23/GNU++23 and tweak the diagnostics
for C++ otherwise, + testsuite coverage.
The diagnostic wording is similar e.g. to the #elifdef diagnostics.
So far lightly tested, ok for trunk if it passes full bootstrap/regtest?
2022-08-22 Jakub Jelinek <jakub@redhat.com>
PR c++/106646
* init.cc: Implement C++23 P2437R1 - Support for #warning.
(lang_defaults): Set warning_directive for GNUCXX23 and CXX23.
* directives.cc (directive_diagnostics): Use different wording of
#warning pedwarn for C++.
* g++.dg/cpp/warning-1.C: New test.
* g++.dg/cpp/warning-2.C: New test.
* g++.dg/cpp/warning-3.C: New test.
--- libcpp/init.cc.jj 2022-08-20 10:25:17.613071845 +0200
+++ libcpp/init.cc 2022-08-22 11:30:57.642622570 +0200
@@ -123,8 +123,8 @@ static const struct lang_flags lang_defa
/* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0 },
/* GNUCXX20 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
/* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
- /* GNUCXX23 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 },
- /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 },
+ /* GNUCXX23 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1 },
+ /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1 },
/* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
--- libcpp/directives.cc.jj 2022-08-19 16:00:05.295386974 +0200
+++ libcpp/directives.cc 2022-08-22 11:30:03.239357642 +0200
@@ -388,8 +388,14 @@ directive_diagnostics (cpp_reader *pfile
else if (dir == &dtable[T_WARNING])
{
if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, warning_directive))
- cpp_error (pfile, CPP_DL_PEDWARN,
- "#%s before C2X is a GCC extension", dir->name);
+ {
+ if (CPP_OPTION (pfile, cplusplus))
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "#%s before C++23 is a GCC extension", dir->name);
+ else
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "#%s before C2X is a GCC extension", dir->name);
+ }
else if (CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) > 0)
cpp_warning (pfile, CPP_W_C11_C2X_COMPAT,
"#%s before C2X is a GCC extension", dir->name);
--- gcc/testsuite/g++.dg/cpp/warning-1.C.jj 2022-08-22 11:39:41.284547323 +0200
+++ gcc/testsuite/g++.dg/cpp/warning-1.C 2022-08-22 11:44:03.925988332 +0200
@@ -0,0 +1,6 @@
+// P2437R1 - Support for #warning
+// { dg-do preprocess }
+// { dg-options "-pedantic-errors" }
+
+#warning example text /* { dg-warning "example text" } */
+// { dg-error "#warning before C\\\+\\\+23 is a GCC extension" "pedantic" { target c++20_down } .-1 }
--- gcc/testsuite/g++.dg/cpp/warning-2.C.jj 2022-08-22 11:39:44.116509055 +0200
+++ gcc/testsuite/g++.dg/cpp/warning-2.C 2022-08-22 11:44:14.933839041 +0200
@@ -0,0 +1,6 @@
+// P2437R1 - Support for #warning
+// { dg-do preprocess }
+// { dg-options "-pedantic" }
+
+#warning example text /* { dg-warning "example text" } */
+// { dg-warning "#warning before C\\\+\\\+23 is a GCC extension" "pedantic" { target c++20_down } .-1 }
--- gcc/testsuite/g++.dg/cpp/warning-3.C.jj 2022-08-22 11:39:47.020469826 +0200
+++ gcc/testsuite/g++.dg/cpp/warning-3.C 2022-08-22 11:42:23.640348405 +0200
@@ -0,0 +1,6 @@
+// P2437R1 - Support for #warning
+// { dg-do preprocess }
+// { dg-options "" }
+
+#warning example text /* { dg-warning "example text" } */
+// { dg-bogus "#warning before C\\\+\\\+23 is a GCC extension" "" { target *-*-* } .-1 }
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] preprocessor: Implement C++23 P2437R1 - Support for #warning [PR106646]
2022-08-22 9:53 ` [PATCH] preprocessor: Implement C++23 P2437R1 - Support for #warning [PR106646] Jakub Jelinek
@ 2022-08-23 21:54 ` Jason Merrill
0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2022-08-23 21:54 UTC (permalink / raw)
To: Jakub Jelinek, Joseph Myers; +Cc: gcc-patches, Marek Polacek
On 8/22/22 02:53, Jakub Jelinek wrote:
> Hi!
>
> On Thu, Aug 18, 2022 at 11:02:44PM +0000, Joseph Myers wrote:
>> 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.
>
> And here is the corresponding C++ version.
> Don't pedwarn about this for C++23/GNU++23 and tweak the diagnostics
> for C++ otherwise, + testsuite coverage.
> The diagnostic wording is similar e.g. to the #elifdef diagnostics.
>
> So far lightly tested, ok for trunk if it passes full bootstrap/regtest?
OK.
> 2022-08-22 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/106646
> * init.cc: Implement C++23 P2437R1 - Support for #warning.
> (lang_defaults): Set warning_directive for GNUCXX23 and CXX23.
> * directives.cc (directive_diagnostics): Use different wording of
> #warning pedwarn for C++.
>
> * g++.dg/cpp/warning-1.C: New test.
> * g++.dg/cpp/warning-2.C: New test.
> * g++.dg/cpp/warning-3.C: New test.
>
> --- libcpp/init.cc.jj 2022-08-20 10:25:17.613071845 +0200
> +++ libcpp/init.cc 2022-08-22 11:30:57.642622570 +0200
> @@ -123,8 +123,8 @@ static const struct lang_flags lang_defa
> /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0 },
> /* GNUCXX20 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
> /* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
> - /* GNUCXX23 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 },
> - /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 },
> + /* GNUCXX23 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1 },
> + /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1 },
> /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
> };
>
> --- libcpp/directives.cc.jj 2022-08-19 16:00:05.295386974 +0200
> +++ libcpp/directives.cc 2022-08-22 11:30:03.239357642 +0200
> @@ -388,8 +388,14 @@ directive_diagnostics (cpp_reader *pfile
> else if (dir == &dtable[T_WARNING])
> {
> if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, warning_directive))
> - cpp_error (pfile, CPP_DL_PEDWARN,
> - "#%s before C2X is a GCC extension", dir->name);
> + {
> + if (CPP_OPTION (pfile, cplusplus))
> + cpp_error (pfile, CPP_DL_PEDWARN,
> + "#%s before C++23 is a GCC extension", dir->name);
> + else
> + cpp_error (pfile, CPP_DL_PEDWARN,
> + "#%s before C2X is a GCC extension", dir->name);
> + }
> else if (CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) > 0)
> cpp_warning (pfile, CPP_W_C11_C2X_COMPAT,
> "#%s before C2X is a GCC extension", dir->name);
> --- gcc/testsuite/g++.dg/cpp/warning-1.C.jj 2022-08-22 11:39:41.284547323 +0200
> +++ gcc/testsuite/g++.dg/cpp/warning-1.C 2022-08-22 11:44:03.925988332 +0200
> @@ -0,0 +1,6 @@
> +// P2437R1 - Support for #warning
> +// { dg-do preprocess }
> +// { dg-options "-pedantic-errors" }
> +
> +#warning example text /* { dg-warning "example text" } */
> +// { dg-error "#warning before C\\\+\\\+23 is a GCC extension" "pedantic" { target c++20_down } .-1 }
> --- gcc/testsuite/g++.dg/cpp/warning-2.C.jj 2022-08-22 11:39:44.116509055 +0200
> +++ gcc/testsuite/g++.dg/cpp/warning-2.C 2022-08-22 11:44:14.933839041 +0200
> @@ -0,0 +1,6 @@
> +// P2437R1 - Support for #warning
> +// { dg-do preprocess }
> +// { dg-options "-pedantic" }
> +
> +#warning example text /* { dg-warning "example text" } */
> +// { dg-warning "#warning before C\\\+\\\+23 is a GCC extension" "pedantic" { target c++20_down } .-1 }
> --- gcc/testsuite/g++.dg/cpp/warning-3.C.jj 2022-08-22 11:39:47.020469826 +0200
> +++ gcc/testsuite/g++.dg/cpp/warning-3.C 2022-08-22 11:42:23.640348405 +0200
> @@ -0,0 +1,6 @@
> +// P2437R1 - Support for #warning
> +// { dg-do preprocess }
> +// { dg-options "" }
> +
> +#warning example text /* { dg-warning "example text" } */
> +// { dg-bogus "#warning before C\\\+\\\+23 is a GCC extension" "" { target *-*-* } .-1 }
>
>
> Jakub
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-08-23 21:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-18 23:02 [committed] preprocessor: Support #warning for standard C2x Joseph Myers
2022-08-22 9:53 ` [PATCH] preprocessor: Implement C++23 P2437R1 - Support for #warning [PR106646] Jakub Jelinek
2022-08-23 21:54 ` Jason Merrill
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).