From 365202625d2f2d6694dba889ca67498fefb59c68 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 24 Aug 2022 09:55:57 +0200 Subject: preprocessor: Implement C++23 P2437R1 - Support for #warning [PR106646] 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. 2022-08-24 Jakub Jelinek 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. --- gcc/testsuite/g++.dg/cpp/warning-1.C | 6 ++++++ gcc/testsuite/g++.dg/cpp/warning-2.C | 6 ++++++ gcc/testsuite/g++.dg/cpp/warning-3.C | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp/warning-1.C create mode 100644 gcc/testsuite/g++.dg/cpp/warning-2.C create mode 100644 gcc/testsuite/g++.dg/cpp/warning-3.C (limited to 'gcc') diff --git a/gcc/testsuite/g++.dg/cpp/warning-1.C b/gcc/testsuite/g++.dg/cpp/warning-1.C new file mode 100644 index 0000000..2d857cf --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp/warning-1.C @@ -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 } diff --git a/gcc/testsuite/g++.dg/cpp/warning-2.C b/gcc/testsuite/g++.dg/cpp/warning-2.C new file mode 100644 index 0000000..d6d5d9f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp/warning-2.C @@ -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 } diff --git a/gcc/testsuite/g++.dg/cpp/warning-3.C b/gcc/testsuite/g++.dg/cpp/warning-3.C new file mode 100644 index 0000000..1595b4d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp/warning-3.C @@ -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 } -- cgit v1.1