From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>, Joseph Myers <joseph@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org, Marek Polacek <polacek@redhat.com>
Subject: [PATCH] preprocessor: Implement C++23 P2437R1 - Support for #warning [PR106646]
Date: Mon, 22 Aug 2022 11:53:33 +0200 [thread overview]
Message-ID: <YwNSHY8mx41NB1jF@tucnak> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2208182301330.72069@digraph.polyomino.org.uk>
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
next prev parent reply other threads:[~2022-08-22 9:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-18 23:02 [committed] preprocessor: Support #warning for standard C2x Joseph Myers
2022-08-22 9:53 ` Jakub Jelinek [this message]
2022-08-23 21:54 ` [PATCH] preprocessor: Implement C++23 P2437R1 - Support for #warning [PR106646] Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YwNSHY8mx41NB1jF@tucnak \
--to=jakub@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=joseph@codesourcery.com \
--cc=polacek@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).