From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id EEE3F3857034; Wed, 24 Aug 2022 07:56:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EEE3F3857034 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661327803; bh=F3Eu8HGBtA8ZZLx0fGVJah3buQEmPe0cIawCQOgudFQ=; h=From:To:Subject:Date:From; b=ukWjsWM4G9ERzjhUpe1ROJJzp84s5HbVb3BNtOMPCM4MGEHcFcxke0HyFukURFge7 Ic2xg8mOjLMFdVBKhG31y6jWc+JUrz3UohWm6p7dTykB10fo8JSZLyAspDA5j046GA M2QZQmIwOMRxP23d8jXIZdsxxzVxi1JoIJCphO9E= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2167] preprocessor: Implement C++23 P2437R1 - Support for #warning [PR106646] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 42301c02e458cdce646ffaf7ea1df502ab2e8ddc X-Git-Newrev: 365202625d2f2d6694dba889ca67498fefb59c68 Message-Id: <20220824075643.EEE3F3857034@sourceware.org> Date: Wed, 24 Aug 2022 07:56:43 +0000 (GMT) List-Id: https://gcc.gnu.org/g:365202625d2f2d6694dba889ca67498fefb59c68 commit r13-2167-g365202625d2f2d6694dba889ca67498fefb59c68 Author: Jakub Jelinek Date: Wed Aug 24 09:55:57 2022 +0200 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. Diff: --- 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 ++++++ libcpp/directives.cc | 10 ++++++++-- libcpp/init.cc | 4 ++-- 5 files changed, 28 insertions(+), 4 deletions(-) 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 00000000000..2d857cf747c --- /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 00000000000..d6d5d9fc081 --- /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 00000000000..1595b4d1305 --- /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 } diff --git a/libcpp/directives.cc b/libcpp/directives.cc index 802bd8c8bb5..918752f6b1f 100644 --- a/libcpp/directives.cc +++ b/libcpp/directives.cc @@ -388,8 +388,14 @@ directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented) 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); diff --git a/libcpp/init.cc b/libcpp/init.cc index b184e1ffd99..39e7e75f010 100644 --- a/libcpp/init.cc +++ b/libcpp/init.cc @@ -123,8 +123,8 @@ static const struct lang_flags lang_defaults[] = /* 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 } };