public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/1] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics
@ 2022-07-24  4:39 Tom Honermann
  2022-07-24  4:39 ` [PATCH 1/1] " Tom Honermann
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Honermann @ 2022-07-24  4:39 UTC (permalink / raw)
  To: gcc-patches

This change addresses the following issue raised on the libc-alpha mailing list:
  https://sourceware.org/pipermail/libc-alpha/2022-July/140825.html
Glibc 2.36 adds a char8_t typedef in C++ modes that do not enable the char8_t
builtin type (C++17 and earlier by default; subject to _GNU_SOURCE and use of
the -f[no-]char8_t option).  When -Wc++20-compat diagnostics are enabled, the
following warning is issued from the glibc uchar.h header.
  warning: identifier ‘char8_t’ is a keyword in C++20 [-Wc++20-compat]
Such diagnostics are not desired from system headers, so glibc would like to
suppress the diagnostic using '#pragma GCC diagnostic ignored "-Wc++20-compat"',
but attempting to do so currently fails.  This patch corrects that.

Tom Honermann (1):
  c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics.

 gcc/c-family/c-opts.cc                 |  7 +++++++
 gcc/c-family/c.opt                     |  2 +-
 gcc/testsuite/g++.dg/cpp0x/keywords2.C | 16 ++++++++++++++++
 gcc/testsuite/g++.dg/cpp2a/keywords2.C | 13 +++++++++++++
 libcpp/include/cpplib.h                |  4 ++++
 libcpp/init.cc                         |  1 +
 6 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/keywords2.C
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/keywords2.C

-- 
2.32.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/1] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics.
  2022-07-24  4:39 [PATCH 0/1] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics Tom Honermann
@ 2022-07-24  4:39 ` Tom Honermann
  2022-07-27 23:09   ` Joseph Myers
  2022-08-01 18:49   ` [PATCH 1/1 v2] " Tom Honermann
  0 siblings, 2 replies; 10+ messages in thread
From: Tom Honermann @ 2022-07-24  4:39 UTC (permalink / raw)
  To: gcc-patches

Gcc's '#pragma GCC diagnostic' directives are processed in "early mode"
(see handle_pragma_diagnostic_early) for the C++ frontend and, as such,
require that the target diagnostic option be enabled for the preprocessor
(see c_option_is_from_cpp_diagnostics).  This change modifies the
-Wc++20-compat option definition to register it as a preprocessor option
so that its associated diagnostics can be suppressed.  The changes also
implicitly disable the option in C++20 and later modes.  These changes
are consistent with the definition of the -Wc++11-compat option.

This support is motivated by the need to suppress the following diagnostic
otherwise issued in C++17 and earlier modes due to the char8_t typedef
present in the uchar.h header file in glibc 2.36.
  warning: identifier ‘char8_t’ is a keyword in C++20 [-Wc++20-compat]

Tests are added to validate suppression of both -Wc++11-compat and
-Wc++20-compat related diagnostics (fixes were only needed for the C++20
case).

Fixes https://gcc.gnu.org/PR106423.

gcc/c-family/ChangeLog:
	* c-opts.cc (c_common_post_options): Disable -Wc++20-compat diagnostics
	in C++20 and later.
	* c.opt (Wc++20-compat): Enable hooks for the preprocessor.

gcc/testsuite/ChangeLog:
	* g++.dg/cpp0x/keywords2.C: New test.
	* g++.dg/cpp2a/keywords2.C: New test.

libcpp/ChangeLog:
	* include/cpplib.h (cpp_warning_reason): Add CPP_W_CXX20_COMPAT.
	* init.cc (cpp_create_reader): Add cpp_warn_cxx20_compat.
---
 gcc/c-family/c-opts.cc                 |  7 +++++++
 gcc/c-family/c.opt                     |  2 +-
 gcc/testsuite/g++.dg/cpp0x/keywords2.C | 16 ++++++++++++++++
 gcc/testsuite/g++.dg/cpp2a/keywords2.C | 13 +++++++++++++
 libcpp/include/cpplib.h                |  4 ++++
 libcpp/init.cc                         |  1 +
 6 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/keywords2.C
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/keywords2.C

diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index b9f01a65ed7..1ea37ba9742 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -1046,6 +1046,13 @@ c_common_post_options (const char **pfilename)
   else if (warn_narrowing == -1)
     warn_narrowing = 0;
 
+  if (cxx_dialect >= cxx20)
+    {
+      /* Don't warn about C++20 compatibility changes in C++20 or later.  */
+      warn_cxx20_compat = 0;
+      cpp_opts->cpp_warn_cxx20_compat = 0;
+    }
+
   /* C++17 has stricter evaluation order requirements; let's use some of them
      for earlier C++ as well, so chaining works as expected.  */
   if (c_dialect_cxx ()
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 44e1a60ce24..dfdebd596ef 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -455,7 +455,7 @@ Wc++2a-compat
 C++ ObjC++ Warning Alias(Wc++20-compat) Undocumented
 
 Wc++20-compat
-C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall)
+C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall) Init(0) CPP(cpp_warn_cxx20_compat) CppReason(CPP_W_CXX20_COMPAT)
 Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020.
 
 Wc++11-extensions
diff --git a/gcc/testsuite/g++.dg/cpp0x/keywords2.C b/gcc/testsuite/g++.dg/cpp0x/keywords2.C
new file mode 100644
index 00000000000..d67d01e31ed
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/keywords2.C
@@ -0,0 +1,16 @@
+// { dg-do compile { target c++98_only } }
+// { dg-options "-Wc++11-compat" }
+
+// Validate suppression of -Wc++11-compat diagnostics.
+#pragma GCC diagnostic ignored "-Wc++11-compat"
+int alignof;
+int alignas;
+int constexpr;
+int decltype;
+int noexcept;
+int nullptr;
+int static_assert;
+int thread_local;
+int _Alignas;
+int _Alignof;
+int _Thread_local;
diff --git a/gcc/testsuite/g++.dg/cpp2a/keywords2.C b/gcc/testsuite/g++.dg/cpp2a/keywords2.C
new file mode 100644
index 00000000000..8714a7b26b7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/keywords2.C
@@ -0,0 +1,13 @@
+// { dg-do compile { target c++17_down } }
+// { dg-options "-Wc++20-compat" }
+
+// Validate suppression of -Wc++20-compat diagnostics.
+#pragma GCC diagnostic ignored "-Wc++20-compat"
+int constinit;
+int consteval;
+int requires;
+int concept;
+int co_await;
+int co_yield;
+int co_return;
+int char8_t;
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 3eba6f74b57..9d90c18e4f2 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -547,6 +547,9 @@ struct cpp_options
   /* True if warn about differences between C++98 and C++11.  */
   bool cpp_warn_cxx11_compat;
 
+  /* True if warn about differences between C++17 and C++20.  */
+  bool cpp_warn_cxx20_compat;
+
   /* Nonzero if bidirectional control characters checking is on.  See enum
      cpp_bidirectional_level.  */
   unsigned char cpp_warn_bidirectional;
@@ -655,6 +658,7 @@ enum cpp_warning_reason {
   CPP_W_C90_C99_COMPAT,
   CPP_W_C11_C2X_COMPAT,
   CPP_W_CXX11_COMPAT,
+  CPP_W_CXX20_COMPAT,
   CPP_W_EXPANSION_TO_DEFINED,
   CPP_W_BIDIRECTIONAL
 };
diff --git a/libcpp/init.cc b/libcpp/init.cc
index f4ab83d2145..cca3c1dc1e7 100644
--- a/libcpp/init.cc
+++ b/libcpp/init.cc
@@ -202,6 +202,7 @@ cpp_create_reader (enum c_lang lang, cpp_hash_table *table,
   CPP_OPTION (pfile, cpp_warn_c90_c99_compat) = -1;
   CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) = -1;
   CPP_OPTION (pfile, cpp_warn_cxx11_compat) = 0;
+  CPP_OPTION (pfile, cpp_warn_cxx20_compat) = 0;
   CPP_OPTION (pfile, cpp_warn_deprecated) = 1;
   CPP_OPTION (pfile, cpp_warn_long_long) = 0;
   CPP_OPTION (pfile, dollars_in_ident) = 1;
-- 
2.32.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics.
  2022-07-24  4:39 ` [PATCH 1/1] " Tom Honermann
@ 2022-07-27 23:09   ` Joseph Myers
  2022-07-30 23:05     ` Tom Honermann
  2022-08-01 18:49   ` [PATCH 1/1 v2] " Tom Honermann
  1 sibling, 1 reply; 10+ messages in thread
From: Joseph Myers @ 2022-07-27 23:09 UTC (permalink / raw)
  To: Tom Honermann; +Cc: gcc-patches

On Sun, 24 Jul 2022, Tom Honermann via Gcc-patches wrote:

> Gcc's '#pragma GCC diagnostic' directives are processed in "early mode"
> (see handle_pragma_diagnostic_early) for the C++ frontend and, as such,
> require that the target diagnostic option be enabled for the preprocessor
> (see c_option_is_from_cpp_diagnostics).  This change modifies the
> -Wc++20-compat option definition to register it as a preprocessor option
> so that its associated diagnostics can be suppressed.  The changes also

There are lots of C++ warning options, all of which should support pragma 
suppression regardless of whether they are relevant to the preprocessor or 
not.  Do they all need this kind of handling, or is it only -Wc++20-compat 
that has some kind of problem?

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics.
  2022-07-27 23:09   ` Joseph Myers
@ 2022-07-30 23:05     ` Tom Honermann
  2022-07-31 15:05       ` Lewis Hyatt
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Honermann @ 2022-07-30 23:05 UTC (permalink / raw)
  To: Joseph Myers; +Cc: gcc-patches

On 7/27/22 7:09 PM, Joseph Myers wrote:
> On Sun, 24 Jul 2022, Tom Honermann via Gcc-patches wrote:
>
>> Gcc's '#pragma GCC diagnostic' directives are processed in "early mode"
>> (see handle_pragma_diagnostic_early) for the C++ frontend and, as such,
>> require that the target diagnostic option be enabled for the preprocessor
>> (see c_option_is_from_cpp_diagnostics).  This change modifies the
>> -Wc++20-compat option definition to register it as a preprocessor option
>> so that its associated diagnostics can be suppressed.  The changes also
> There are lots of C++ warning options, all of which should support pragma
> suppression regardless of whether they are relevant to the preprocessor or
> not.  Do they all need this kind of handling, or is it only -Wc++20-compat
> that has some kind of problem?

I had only checked -Wc++20-compat when working on the patch.

I did some spot checking now and confirmed that suppression works as 
expected for C++ for at least the following warnings:
   -Wuninitialized
   -Warray-compare
   -Wbool-compare
   -Wtautological-compare
   -Wterminate

I don't know the diagnostic framework well. As best I can tell, this 
issue is specific to the -Wc++20-compat option and when the particular 
diagnostic is issued (e.g., during lexing as opposed to during parsing). 
The following call chains appear to be relevant.
   cp_lexer_new_main -> cp_lexer_handle_early_pragma -> 
c_invoke_early_pragma_handler
   cp_parser_* -> cp_parser_pragma -> c_invoke_pragma_handler
   (where * might be "declaration", "toplevel_declaration", 
"class_head", "objc_interstitial_code", ...)

The -Wc++20-compat enabled warning regarding new keywords in C++20 is 
issued from cp_lexer_get_preprocessor_token.

Tom.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics.
  2022-07-30 23:05     ` Tom Honermann
@ 2022-07-31 15:05       ` Lewis Hyatt
  2022-07-31 21:41         ` Tom Honermann
  0 siblings, 1 reply; 10+ messages in thread
From: Lewis Hyatt @ 2022-07-31 15:05 UTC (permalink / raw)
  To: Tom Honermann, Joseph Myers; +Cc: gcc-patches List

On Sat, Jul 30, 2022 at 7:06 PM Tom Honermann via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On 7/27/22 7:09 PM, Joseph Myers wrote:
> > On Sun, 24 Jul 2022, Tom Honermann via Gcc-patches wrote:
> >
> >> Gcc's '#pragma GCC diagnostic' directives are processed in "early mode"
> >> (see handle_pragma_diagnostic_early) for the C++ frontend and, as such,
> >> require that the target diagnostic option be enabled for the preprocessor
> >> (see c_option_is_from_cpp_diagnostics).  This change modifies the
> >> -Wc++20-compat option definition to register it as a preprocessor option
> >> so that its associated diagnostics can be suppressed.  The changes also
> > There are lots of C++ warning options, all of which should support pragma
> > suppression regardless of whether they are relevant to the preprocessor or
> > not.  Do they all need this kind of handling, or is it only -Wc++20-compat
> > that has some kind of problem?
>
> I had only checked -Wc++20-compat when working on the patch.
>
> I did some spot checking now and confirmed that suppression works as
> expected for C++ for at least the following warnings:
>    -Wuninitialized
>    -Warray-compare
>    -Wbool-compare
>    -Wtautological-compare
>    -Wterminate
>
> I don't know the diagnostic framework well. As best I can tell, this
> issue is specific to the -Wc++20-compat option and when the particular
> diagnostic is issued (e.g., during lexing as opposed to during parsing).
> The following call chains appear to be relevant.
>    cp_lexer_new_main -> cp_lexer_handle_early_pragma ->
> c_invoke_early_pragma_handler
>    cp_parser_* -> cp_parser_pragma -> c_invoke_pragma_handler
>    (where * might be "declaration", "toplevel_declaration",
> "class_head", "objc_interstitial_code", ...)
>
> The -Wc++20-compat enabled warning regarding new keywords in C++20 is
> issued from cp_lexer_get_preprocessor_token.
>
> Tom.
>

I have been working on improving the handling of "#pragma GCC
diagnostic" lately. The behavior for C++ changed since r13-1544
(https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=e46f4d7430c5210465791603735ab219ef263c51).
I have some more comments about the patch's approach on the PR
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431#c44).

"#pragma GCC diagnostic" formerly did not work in C++ at all, for
diagnostics generated by libcpp, because C++ obtains all the tokens
from libcpp first (including deferred pragmas), and then processes
them afterward, too late to take effect for diagnostics that libcpp
has already emitted. r13-1544 fixed this up by adding an early pragma
handler, which runs as soon as a deferred pragma token is seen and
handles diagnostic pragmas if they pertain to libcpp-controlled
diagnostics. Non-libcpp diagnostics still need to be handled later,
during parsing, or else they get processed too early and it leads to
other problems. Basically, now each diagnostic pragma is handled as
close in time as possible to the time the associated diagnostics might
be generated.

The early pragma handler determines that an option comes from libcpp,
and so should be subject to early processing, if it was marked as such
in the options definition file. Tom's patch points out that
-Wc++20-compat needs to be handled early, and so marking it as a
libcpp diagnostic in c-family/c.opt arranges for that to work as
intended. Now one potential objection here is that -Wc++20-compat
warnings are not technically generated by libcpp. They are generated
by the C++ frontend immediately after lexing an identifier token from
libcpp (cp_lexer_get_preprocessor_token()). But the distinction
between these two steps is rather blurry and it seems logical to me,
to denote this as a libcpp-related option. Also, the same is already
done for -Wc++11-compat. Otherwise, we would need to add some new
option property to indicate which ones need to be handled for pragmas
at lexing time rather than parsing time.

At the moment I don't see any other diagnostics issued from
cp_lexer_get_preprocessor_token() that would need similar adjustments.
Assuming the approach is OK, it might be nice to add a comment to that
function, indicating that any diagnostics emitted there should be
annotated as libcpp options in the .opt file?

-Lewis

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics.
  2022-07-31 15:05       ` Lewis Hyatt
@ 2022-07-31 21:41         ` Tom Honermann
  0 siblings, 0 replies; 10+ messages in thread
From: Tom Honermann @ 2022-07-31 21:41 UTC (permalink / raw)
  To: Lewis Hyatt, Joseph Myers; +Cc: gcc-patches List

On 7/31/22 11:05 AM, Lewis Hyatt wrote:
> On Sat, Jul 30, 2022 at 7:06 PM Tom Honermann via Gcc-patches
> <gcc-patches@gcc.gnu.org>  wrote:
>> On 7/27/22 7:09 PM, Joseph Myers wrote:
>>> On Sun, 24 Jul 2022, Tom Honermann via Gcc-patches wrote:
>>>
>>>> Gcc's '#pragma GCC diagnostic' directives are processed in "early mode"
>>>> (see handle_pragma_diagnostic_early) for the C++ frontend and, as such,
>>>> require that the target diagnostic option be enabled for the preprocessor
>>>> (see c_option_is_from_cpp_diagnostics).  This change modifies the
>>>> -Wc++20-compat option definition to register it as a preprocessor option
>>>> so that its associated diagnostics can be suppressed.  The changes also
>>> There are lots of C++ warning options, all of which should support pragma
>>> suppression regardless of whether they are relevant to the preprocessor or
>>> not.  Do they all need this kind of handling, or is it only -Wc++20-compat
>>> that has some kind of problem?
>> I had only checked -Wc++20-compat when working on the patch.
>>
>> I did some spot checking now and confirmed that suppression works as
>> expected for C++ for at least the following warnings:
>>     -Wuninitialized
>>     -Warray-compare
>>     -Wbool-compare
>>     -Wtautological-compare
>>     -Wterminate
>>
>> I don't know the diagnostic framework well. As best I can tell, this
>> issue is specific to the -Wc++20-compat option and when the particular
>> diagnostic is issued (e.g., during lexing as opposed to during parsing).
>> The following call chains appear to be relevant.
>>     cp_lexer_new_main -> cp_lexer_handle_early_pragma ->
>> c_invoke_early_pragma_handler
>>     cp_parser_* -> cp_parser_pragma -> c_invoke_pragma_handler
>>     (where * might be "declaration", "toplevel_declaration",
>> "class_head", "objc_interstitial_code", ...)
>>
>> The -Wc++20-compat enabled warning regarding new keywords in C++20 is
>> issued from cp_lexer_get_preprocessor_token.
>>
>> Tom.
>>
> I have been working on improving the handling of "#pragma GCC
> diagnostic" lately. The behavior for C++ changed since r13-1544
> (https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=e46f4d7430c5210465791603735ab219ef263c51).
> I have some more comments about the patch's approach on the PR
> (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431#c44).
>
> "#pragma GCC diagnostic" formerly did not work in C++ at all, for
> diagnostics generated by libcpp, because C++ obtains all the tokens
> from libcpp first (including deferred pragmas), and then processes
> them afterward, too late to take effect for diagnostics that libcpp
> has already emitted. r13-1544 fixed this up by adding an early pragma
> handler, which runs as soon as a deferred pragma token is seen and
> handles diagnostic pragmas if they pertain to libcpp-controlled
> diagnostics. Non-libcpp diagnostics still need to be handled later,
> during parsing, or else they get processed too early and it leads to
> other problems. Basically, now each diagnostic pragma is handled as
> close in time as possible to the time the associated diagnostics might
> be generated.
>
> The early pragma handler determines that an option comes from libcpp,
> and so should be subject to early processing, if it was marked as such
> in the options definition file. Tom's patch points out that
> -Wc++20-compat needs to be handled early, and so marking it as a
> libcpp diagnostic in c-family/c.opt arranges for that to work as
> intended. Now one potential objection here is that -Wc++20-compat
> warnings are not technically generated by libcpp. They are generated
> by the C++ frontend immediately after lexing an identifier token from
> libcpp (cp_lexer_get_preprocessor_token()). But the distinction
> between these two steps is rather blurry and it seems logical to me,
> to denote this as a libcpp-related option. Also, the same is already
> done for -Wc++11-compat. Otherwise, we would need to add some new
> option property to indicate which ones need to be handled for pragmas
> at lexing time rather than parsing time.
>
> At the moment I don't see any other diagnostics issued from
> cp_lexer_get_preprocessor_token() that would need similar adjustments.
> Assuming the approach is OK, it might be nice to add a comment to that
> function, indicating that any diagnostics emitted there should be
> annotated as libcpp options in the .opt file?

Thank you for those details; I wasn't aware of that history.

If I'm interpreting your response correctly, it sounds like you agree 
with the direction of the patch.

If you like, I can add a comment as you suggested and re-post the patch. 
Perhaps:

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 4f67441eeb1..c3584446827 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -924,7 +924,10 @@cp_lexer_saving_tokens (const cp_lexer* lexer)
/* Store the next token from the preprocessor in *TOKEN.  Return true
    if we reach EOF.  If LEXER is NULL, assume we are handling an
    initial #pragma pch_preprocess, and thus want the lexer to return
-   processed strings.  */
+   processed strings.
+
+   Diagnostics issued from this function must have their controlling 
option (if
+   any) in c.opt annotated as a libcpp option via the CppReason 
property.  */

static void
cp_lexer_get_preprocessor_token (unsigned flags, cp_token *token)

Tom.

> -Lewis

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/1 v2] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics.
  2022-07-24  4:39 ` [PATCH 1/1] " Tom Honermann
  2022-07-27 23:09   ` Joseph Myers
@ 2022-08-01 18:49   ` Tom Honermann
  2022-08-04 16:42     ` Tom Honermann
  1 sibling, 1 reply; 10+ messages in thread
From: Tom Honermann @ 2022-08-01 18:49 UTC (permalink / raw)
  To: gcc-patches

Gcc's '#pragma GCC diagnostic' directives are processed in "early mode"
(see handle_pragma_diagnostic_early) for the C++ frontend and, as such,
require that the target diagnostic option be enabled for the preprocessor
(see c_option_is_from_cpp_diagnostics).  This change modifies the
-Wc++20-compat option definition to register it as a preprocessor option
so that its associated diagnostics can be suppressed.  The changes also
implicitly disable the option in C++20 and later modes.  These changes
are consistent with the definition of the -Wc++11-compat option.

This support is motivated by the need to suppress the following diagnostic
otherwise issued in C++17 and earlier modes due to the char8_t typedef
present in the uchar.h header file in glibc 2.36.
  warning: identifier ‘char8_t’ is a keyword in C++20 [-Wc++20-compat]

Tests are added to validate suppression of both -Wc++11-compat and
-Wc++20-compat related diagnostics (fixes were only needed for the C++20
case).

Fixes https://gcc.gnu.org/PR106423.

gcc/c-family/ChangeLog:
	* c-opts.cc (c_common_post_options): Disable -Wc++20-compat diagnostics
	in C++20 and later.
	* c.opt (Wc++20-compat): Enable hooks for the preprocessor.

gcc/testsuite/ChangeLog:
	* g++.dg/cpp0x/keywords2.C: New test.
	* g++.dg/cpp2a/keywords2.C: New test.

libcpp/ChangeLog:
	* include/cpplib.h (cpp_warning_reason): Add CPP_W_CXX20_COMPAT.
	* init.cc (cpp_create_reader): Add cpp_warn_cxx20_compat.
---
 gcc/c-family/c-opts.cc                 |  7 +++++++
 gcc/c-family/c.opt                     |  2 +-
 gcc/cp/parser.cc                       |  5 ++++-
 gcc/testsuite/g++.dg/cpp0x/keywords2.C | 16 ++++++++++++++++
 gcc/testsuite/g++.dg/cpp2a/keywords2.C | 13 +++++++++++++
 libcpp/include/cpplib.h                |  4 ++++
 libcpp/init.cc                         |  1 +
 7 files changed, 46 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/keywords2.C
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/keywords2.C

diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index b9f01a65ed7..1ea37ba9742 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -1046,6 +1046,13 @@ c_common_post_options (const char **pfilename)
   else if (warn_narrowing == -1)
     warn_narrowing = 0;
 
+  if (cxx_dialect >= cxx20)
+    {
+      /* Don't warn about C++20 compatibility changes in C++20 or later.  */
+      warn_cxx20_compat = 0;
+      cpp_opts->cpp_warn_cxx20_compat = 0;
+    }
+
   /* C++17 has stricter evaluation order requirements; let's use some of them
      for earlier C++ as well, so chaining works as expected.  */
   if (c_dialect_cxx ()
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 44e1a60ce24..dfdebd596ef 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -455,7 +455,7 @@ Wc++2a-compat
 C++ ObjC++ Warning Alias(Wc++20-compat) Undocumented
 
 Wc++20-compat
-C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall)
+C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall) Init(0) CPP(cpp_warn_cxx20_compat) CppReason(CPP_W_CXX20_COMPAT)
 Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020.
 
 Wc++11-extensions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 4f67441eeb1..c3584446827 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -924,7 +924,10 @@ cp_lexer_saving_tokens (const cp_lexer* lexer)
 /* Store the next token from the preprocessor in *TOKEN.  Return true
    if we reach EOF.  If LEXER is NULL, assume we are handling an
    initial #pragma pch_preprocess, and thus want the lexer to return
-   processed strings.  */
+   processed strings.
+
+   Diagnostics issued from this function must have their controlling option (if
+   any) in c.opt annotated as a libcpp option via the CppReason property.  */
 
 static void
 cp_lexer_get_preprocessor_token (unsigned flags, cp_token *token)
diff --git a/gcc/testsuite/g++.dg/cpp0x/keywords2.C b/gcc/testsuite/g++.dg/cpp0x/keywords2.C
new file mode 100644
index 00000000000..d67d01e31ed
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/keywords2.C
@@ -0,0 +1,16 @@
+// { dg-do compile { target c++98_only } }
+// { dg-options "-Wc++11-compat" }
+
+// Validate suppression of -Wc++11-compat diagnostics.
+#pragma GCC diagnostic ignored "-Wc++11-compat"
+int alignof;
+int alignas;
+int constexpr;
+int decltype;
+int noexcept;
+int nullptr;
+int static_assert;
+int thread_local;
+int _Alignas;
+int _Alignof;
+int _Thread_local;
diff --git a/gcc/testsuite/g++.dg/cpp2a/keywords2.C b/gcc/testsuite/g++.dg/cpp2a/keywords2.C
new file mode 100644
index 00000000000..8714a7b26b7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/keywords2.C
@@ -0,0 +1,13 @@
+// { dg-do compile { target c++17_down } }
+// { dg-options "-Wc++20-compat" }
+
+// Validate suppression of -Wc++20-compat diagnostics.
+#pragma GCC diagnostic ignored "-Wc++20-compat"
+int constinit;
+int consteval;
+int requires;
+int concept;
+int co_await;
+int co_yield;
+int co_return;
+int char8_t;
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 3eba6f74b57..9d90c18e4f2 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -547,6 +547,9 @@ struct cpp_options
   /* True if warn about differences between C++98 and C++11.  */
   bool cpp_warn_cxx11_compat;
 
+  /* True if warn about differences between C++17 and C++20.  */
+  bool cpp_warn_cxx20_compat;
+
   /* Nonzero if bidirectional control characters checking is on.  See enum
      cpp_bidirectional_level.  */
   unsigned char cpp_warn_bidirectional;
@@ -655,6 +658,7 @@ enum cpp_warning_reason {
   CPP_W_C90_C99_COMPAT,
   CPP_W_C11_C2X_COMPAT,
   CPP_W_CXX11_COMPAT,
+  CPP_W_CXX20_COMPAT,
   CPP_W_EXPANSION_TO_DEFINED,
   CPP_W_BIDIRECTIONAL
 };
diff --git a/libcpp/init.cc b/libcpp/init.cc
index f4ab83d2145..cca3c1dc1e7 100644
--- a/libcpp/init.cc
+++ b/libcpp/init.cc
@@ -202,6 +202,7 @@ cpp_create_reader (enum c_lang lang, cpp_hash_table *table,
   CPP_OPTION (pfile, cpp_warn_c90_c99_compat) = -1;
   CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) = -1;
   CPP_OPTION (pfile, cpp_warn_cxx11_compat) = 0;
+  CPP_OPTION (pfile, cpp_warn_cxx20_compat) = 0;
   CPP_OPTION (pfile, cpp_warn_deprecated) = 1;
   CPP_OPTION (pfile, cpp_warn_long_long) = 0;
   CPP_OPTION (pfile, dollars_in_ident) = 1;
-- 
2.32.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1 v2] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics.
  2022-08-01 18:49   ` [PATCH 1/1 v2] " Tom Honermann
@ 2022-08-04 16:42     ` Tom Honermann
  2022-08-11 22:44       ` Tom Honermann
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Honermann @ 2022-08-04 16:42 UTC (permalink / raw)
  To: gcc-patches

Are there any further concerns with this patch? If not, I extend my 
gratitude to anyone so kind as to commit this for me as I don't have 
commit access.

I just noticed that I neglected to add a ChangeLog entry for the comment 
addition to gcc/cp/parser.cc. Noted inline below. I can re-send the 
patch with that update if desired.

Tom.

On 8/1/22 2:49 PM, Tom Honermann wrote:
> Gcc's '#pragma GCC diagnostic' directives are processed in "early mode"
> (see handle_pragma_diagnostic_early) for the C++ frontend and, as such,
> require that the target diagnostic option be enabled for the preprocessor
> (see c_option_is_from_cpp_diagnostics).  This change modifies the
> -Wc++20-compat option definition to register it as a preprocessor option
> so that its associated diagnostics can be suppressed.  The changes also
> implicitly disable the option in C++20 and later modes.  These changes
> are consistent with the definition of the -Wc++11-compat option.
>
> This support is motivated by the need to suppress the following diagnostic
> otherwise issued in C++17 and earlier modes due to the char8_t typedef
> present in the uchar.h header file in glibc 2.36.
>    warning: identifier ‘char8_t’ is a keyword in C++20 [-Wc++20-compat]
>
> Tests are added to validate suppression of both -Wc++11-compat and
> -Wc++20-compat related diagnostics (fixes were only needed for the C++20
> case).
>
> Fixeshttps://gcc.gnu.org/PR106423.
>
> gcc/c-family/ChangeLog:
> 	* c-opts.cc (c_common_post_options): Disable -Wc++20-compat diagnostics
> 	in C++20 and later.
> 	* c.opt (Wc++20-compat): Enable hooks for the preprocessor.

gcc/cp/ChangeLog:
     * parser.cc (cp_lexer_saving_tokens): Add comment regarding 
diagnostic requirements.

>
> gcc/testsuite/ChangeLog:
> 	* g++.dg/cpp0x/keywords2.C: New test.
> 	* g++.dg/cpp2a/keywords2.C: New test.
>
> libcpp/ChangeLog:
> 	* include/cpplib.h (cpp_warning_reason): Add CPP_W_CXX20_COMPAT.
> 	* init.cc (cpp_create_reader): Add cpp_warn_cxx20_compat.
> ---
>   gcc/c-family/c-opts.cc                 |  7 +++++++
>   gcc/c-family/c.opt                     |  2 +-
>   gcc/cp/parser.cc                       |  5 ++++-
>   gcc/testsuite/g++.dg/cpp0x/keywords2.C | 16 ++++++++++++++++
>   gcc/testsuite/g++.dg/cpp2a/keywords2.C | 13 +++++++++++++
>   libcpp/include/cpplib.h                |  4 ++++
>   libcpp/init.cc                         |  1 +
>   7 files changed, 46 insertions(+), 2 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/keywords2.C
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/keywords2.C
>
> diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
> index b9f01a65ed7..1ea37ba9742 100644
> --- a/gcc/c-family/c-opts.cc
> +++ b/gcc/c-family/c-opts.cc
> @@ -1046,6 +1046,13 @@ c_common_post_options (const char **pfilename)
>     else if (warn_narrowing == -1)
>       warn_narrowing = 0;
>   
> +  if (cxx_dialect >= cxx20)
> +    {
> +      /* Don't warn about C++20 compatibility changes in C++20 or later.  */
> +      warn_cxx20_compat = 0;
> +      cpp_opts->cpp_warn_cxx20_compat = 0;
> +    }
> +
>     /* C++17 has stricter evaluation order requirements; let's use some of them
>        for earlier C++ as well, so chaining works as expected.  */
>     if (c_dialect_cxx ()
> diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> index 44e1a60ce24..dfdebd596ef 100644
> --- a/gcc/c-family/c.opt
> +++ b/gcc/c-family/c.opt
> @@ -455,7 +455,7 @@ Wc++2a-compat
>   C++ ObjC++ Warning Alias(Wc++20-compat) Undocumented
>   
>   Wc++20-compat
> -C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall)
> +C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall) Init(0) CPP(cpp_warn_cxx20_compat) CppReason(CPP_W_CXX20_COMPAT)
>   Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020.
>   
>   Wc++11-extensions
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index 4f67441eeb1..c3584446827 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -924,7 +924,10 @@ cp_lexer_saving_tokens (const cp_lexer* lexer)
>   /* Store the next token from the preprocessor in *TOKEN.  Return true
>      if we reach EOF.  If LEXER is NULL, assume we are handling an
>      initial #pragma pch_preprocess, and thus want the lexer to return
> -   processed strings.  */
> +   processed strings.
> +
> +   Diagnostics issued from this function must have their controlling option (if
> +   any) in c.opt annotated as a libcpp option via the CppReason property.  */
>   
>   static void
>   cp_lexer_get_preprocessor_token (unsigned flags, cp_token *token)
> diff --git a/gcc/testsuite/g++.dg/cpp0x/keywords2.C b/gcc/testsuite/g++.dg/cpp0x/keywords2.C
> new file mode 100644
> index 00000000000..d67d01e31ed
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/keywords2.C
> @@ -0,0 +1,16 @@
> +// { dg-do compile { target c++98_only } }
> +// { dg-options "-Wc++11-compat" }
> +
> +// Validate suppression of -Wc++11-compat diagnostics.
> +#pragma GCC diagnostic ignored "-Wc++11-compat"
> +int alignof;
> +int alignas;
> +int constexpr;
> +int decltype;
> +int noexcept;
> +int nullptr;
> +int static_assert;
> +int thread_local;
> +int _Alignas;
> +int _Alignof;
> +int _Thread_local;
> diff --git a/gcc/testsuite/g++.dg/cpp2a/keywords2.C b/gcc/testsuite/g++.dg/cpp2a/keywords2.C
> new file mode 100644
> index 00000000000..8714a7b26b7
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/keywords2.C
> @@ -0,0 +1,13 @@
> +// { dg-do compile { target c++17_down } }
> +// { dg-options "-Wc++20-compat" }
> +
> +// Validate suppression of -Wc++20-compat diagnostics.
> +#pragma GCC diagnostic ignored "-Wc++20-compat"
> +int constinit;
> +int consteval;
> +int requires;
> +int concept;
> +int co_await;
> +int co_yield;
> +int co_return;
> +int char8_t;
> diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
> index 3eba6f74b57..9d90c18e4f2 100644
> --- a/libcpp/include/cpplib.h
> +++ b/libcpp/include/cpplib.h
> @@ -547,6 +547,9 @@ struct cpp_options
>     /* True if warn about differences between C++98 and C++11.  */
>     bool cpp_warn_cxx11_compat;
>   
> +  /* True if warn about differences between C++17 and C++20.  */
> +  bool cpp_warn_cxx20_compat;
> +
>     /* Nonzero if bidirectional control characters checking is on.  See enum
>        cpp_bidirectional_level.  */
>     unsigned char cpp_warn_bidirectional;
> @@ -655,6 +658,7 @@ enum cpp_warning_reason {
>     CPP_W_C90_C99_COMPAT,
>     CPP_W_C11_C2X_COMPAT,
>     CPP_W_CXX11_COMPAT,
> +  CPP_W_CXX20_COMPAT,
>     CPP_W_EXPANSION_TO_DEFINED,
>     CPP_W_BIDIRECTIONAL
>   };
> diff --git a/libcpp/init.cc b/libcpp/init.cc
> index f4ab83d2145..cca3c1dc1e7 100644
> --- a/libcpp/init.cc
> +++ b/libcpp/init.cc
> @@ -202,6 +202,7 @@ cpp_create_reader (enum c_lang lang, cpp_hash_table *table,
>     CPP_OPTION (pfile, cpp_warn_c90_c99_compat) = -1;
>     CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) = -1;
>     CPP_OPTION (pfile, cpp_warn_cxx11_compat) = 0;
> +  CPP_OPTION (pfile, cpp_warn_cxx20_compat) = 0;
>     CPP_OPTION (pfile, cpp_warn_deprecated) = 1;
>     CPP_OPTION (pfile, cpp_warn_long_long) = 0;
>     CPP_OPTION (pfile, dollars_in_ident) = 1;

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1 v2] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics.
  2022-08-04 16:42     ` Tom Honermann
@ 2022-08-11 22:44       ` Tom Honermann
  2022-08-11 23:59         ` Jason Merrill
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Honermann @ 2022-08-11 22:44 UTC (permalink / raw)
  To: gcc-patches

If there are no further concerns, could a C++ or libcpp maintainer 
please commit this for me?

Thank you!

Tom.

On 8/4/22 12:42 PM, Tom Honermann via Gcc-patches wrote:
> Are there any further concerns with this patch? If not, I extend my 
> gratitude to anyone so kind as to commit this for me as I don't have 
> commit access.
>
> I just noticed that I neglected to add a ChangeLog entry for the 
> comment addition to gcc/cp/parser.cc. Noted inline below. I can 
> re-send the patch with that update if desired.
>
> Tom.
>
> On 8/1/22 2:49 PM, Tom Honermann wrote:
>> Gcc's '#pragma GCC diagnostic' directives are processed in "early mode"
>> (see handle_pragma_diagnostic_early) for the C++ frontend and, as such,
>> require that the target diagnostic option be enabled for the 
>> preprocessor
>> (see c_option_is_from_cpp_diagnostics).  This change modifies the
>> -Wc++20-compat option definition to register it as a preprocessor option
>> so that its associated diagnostics can be suppressed.  The changes also
>> implicitly disable the option in C++20 and later modes.  These changes
>> are consistent with the definition of the -Wc++11-compat option.
>>
>> This support is motivated by the need to suppress the following 
>> diagnostic
>> otherwise issued in C++17 and earlier modes due to the char8_t typedef
>> present in the uchar.h header file in glibc 2.36.
>>    warning: identifier ‘char8_t’ is a keyword in C++20 [-Wc++20-compat]
>>
>> Tests are added to validate suppression of both -Wc++11-compat and
>> -Wc++20-compat related diagnostics (fixes were only needed for the C++20
>> case).
>>
>> Fixeshttps://gcc.gnu.org/PR106423.
>>
>> gcc/c-family/ChangeLog:
>>     * c-opts.cc (c_common_post_options): Disable -Wc++20-compat 
>> diagnostics
>>     in C++20 and later.
>>     * c.opt (Wc++20-compat): Enable hooks for the preprocessor.
>
> gcc/cp/ChangeLog:
>     * parser.cc (cp_lexer_saving_tokens): Add comment regarding 
> diagnostic requirements.
>
>>
>> gcc/testsuite/ChangeLog:
>>     * g++.dg/cpp0x/keywords2.C: New test.
>>     * g++.dg/cpp2a/keywords2.C: New test.
>>
>> libcpp/ChangeLog:
>>     * include/cpplib.h (cpp_warning_reason): Add CPP_W_CXX20_COMPAT.
>>     * init.cc (cpp_create_reader): Add cpp_warn_cxx20_compat.
>> ---
>>   gcc/c-family/c-opts.cc                 |  7 +++++++
>>   gcc/c-family/c.opt                     |  2 +-
>>   gcc/cp/parser.cc                       |  5 ++++-
>>   gcc/testsuite/g++.dg/cpp0x/keywords2.C | 16 ++++++++++++++++
>>   gcc/testsuite/g++.dg/cpp2a/keywords2.C | 13 +++++++++++++
>>   libcpp/include/cpplib.h                |  4 ++++
>>   libcpp/init.cc                         |  1 +
>>   7 files changed, 46 insertions(+), 2 deletions(-)
>>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/keywords2.C
>>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/keywords2.C
>>
>> diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
>> index b9f01a65ed7..1ea37ba9742 100644
>> --- a/gcc/c-family/c-opts.cc
>> +++ b/gcc/c-family/c-opts.cc
>> @@ -1046,6 +1046,13 @@ c_common_post_options (const char **pfilename)
>>     else if (warn_narrowing == -1)
>>       warn_narrowing = 0;
>>   +  if (cxx_dialect >= cxx20)
>> +    {
>> +      /* Don't warn about C++20 compatibility changes in C++20 or 
>> later.  */
>> +      warn_cxx20_compat = 0;
>> +      cpp_opts->cpp_warn_cxx20_compat = 0;
>> +    }
>> +
>>     /* C++17 has stricter evaluation order requirements; let's use 
>> some of them
>>        for earlier C++ as well, so chaining works as expected. */
>>     if (c_dialect_cxx ()
>> diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
>> index 44e1a60ce24..dfdebd596ef 100644
>> --- a/gcc/c-family/c.opt
>> +++ b/gcc/c-family/c.opt
>> @@ -455,7 +455,7 @@ Wc++2a-compat
>>   C++ ObjC++ Warning Alias(Wc++20-compat) Undocumented
>>     Wc++20-compat
>> -C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ 
>> ObjC++,Wall)
>> +C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ 
>> ObjC++,Wall) Init(0) CPP(cpp_warn_cxx20_compat) 
>> CppReason(CPP_W_CXX20_COMPAT)
>>   Warn about C++ constructs whose meaning differs between ISO C++ 
>> 2017 and ISO C++ 2020.
>>     Wc++11-extensions
>> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
>> index 4f67441eeb1..c3584446827 100644
>> --- a/gcc/cp/parser.cc
>> +++ b/gcc/cp/parser.cc
>> @@ -924,7 +924,10 @@ cp_lexer_saving_tokens (const cp_lexer* lexer)
>>   /* Store the next token from the preprocessor in *TOKEN. Return true
>>      if we reach EOF.  If LEXER is NULL, assume we are handling an
>>      initial #pragma pch_preprocess, and thus want the lexer to return
>> -   processed strings.  */
>> +   processed strings.
>> +
>> +   Diagnostics issued from this function must have their controlling 
>> option (if
>> +   any) in c.opt annotated as a libcpp option via the CppReason 
>> property.  */
>>     static void
>>   cp_lexer_get_preprocessor_token (unsigned flags, cp_token *token)
>> diff --git a/gcc/testsuite/g++.dg/cpp0x/keywords2.C 
>> b/gcc/testsuite/g++.dg/cpp0x/keywords2.C
>> new file mode 100644
>> index 00000000000..d67d01e31ed
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/cpp0x/keywords2.C
>> @@ -0,0 +1,16 @@
>> +// { dg-do compile { target c++98_only } }
>> +// { dg-options "-Wc++11-compat" }
>> +
>> +// Validate suppression of -Wc++11-compat diagnostics.
>> +#pragma GCC diagnostic ignored "-Wc++11-compat"
>> +int alignof;
>> +int alignas;
>> +int constexpr;
>> +int decltype;
>> +int noexcept;
>> +int nullptr;
>> +int static_assert;
>> +int thread_local;
>> +int _Alignas;
>> +int _Alignof;
>> +int _Thread_local;
>> diff --git a/gcc/testsuite/g++.dg/cpp2a/keywords2.C 
>> b/gcc/testsuite/g++.dg/cpp2a/keywords2.C
>> new file mode 100644
>> index 00000000000..8714a7b26b7
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/cpp2a/keywords2.C
>> @@ -0,0 +1,13 @@
>> +// { dg-do compile { target c++17_down } }
>> +// { dg-options "-Wc++20-compat" }
>> +
>> +// Validate suppression of -Wc++20-compat diagnostics.
>> +#pragma GCC diagnostic ignored "-Wc++20-compat"
>> +int constinit;
>> +int consteval;
>> +int requires;
>> +int concept;
>> +int co_await;
>> +int co_yield;
>> +int co_return;
>> +int char8_t;
>> diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
>> index 3eba6f74b57..9d90c18e4f2 100644
>> --- a/libcpp/include/cpplib.h
>> +++ b/libcpp/include/cpplib.h
>> @@ -547,6 +547,9 @@ struct cpp_options
>>     /* True if warn about differences between C++98 and C++11. */
>>     bool cpp_warn_cxx11_compat;
>>   +  /* True if warn about differences between C++17 and C++20. */
>> +  bool cpp_warn_cxx20_compat;
>> +
>>     /* Nonzero if bidirectional control characters checking is on.  
>> See enum
>>        cpp_bidirectional_level.  */
>>     unsigned char cpp_warn_bidirectional;
>> @@ -655,6 +658,7 @@ enum cpp_warning_reason {
>>     CPP_W_C90_C99_COMPAT,
>>     CPP_W_C11_C2X_COMPAT,
>>     CPP_W_CXX11_COMPAT,
>> +  CPP_W_CXX20_COMPAT,
>>     CPP_W_EXPANSION_TO_DEFINED,
>>     CPP_W_BIDIRECTIONAL
>>   };
>> diff --git a/libcpp/init.cc b/libcpp/init.cc
>> index f4ab83d2145..cca3c1dc1e7 100644
>> --- a/libcpp/init.cc
>> +++ b/libcpp/init.cc
>> @@ -202,6 +202,7 @@ cpp_create_reader (enum c_lang lang, 
>> cpp_hash_table *table,
>>     CPP_OPTION (pfile, cpp_warn_c90_c99_compat) = -1;
>>     CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) = -1;
>>     CPP_OPTION (pfile, cpp_warn_cxx11_compat) = 0;
>> +  CPP_OPTION (pfile, cpp_warn_cxx20_compat) = 0;
>>     CPP_OPTION (pfile, cpp_warn_deprecated) = 1;
>>     CPP_OPTION (pfile, cpp_warn_long_long) = 0;
>>     CPP_OPTION (pfile, dollars_in_ident) = 1;

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1 v2] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics.
  2022-08-11 22:44       ` Tom Honermann
@ 2022-08-11 23:59         ` Jason Merrill
  0 siblings, 0 replies; 10+ messages in thread
From: Jason Merrill @ 2022-08-11 23:59 UTC (permalink / raw)
  To: Tom Honermann; +Cc: gcc-patches List

Sorry for the delay, I'm travelling with limited internet. I will commit it
early next week if no one beats me to it.

On Thu, Aug 11, 2022, 2:45 PM Tom Honermann via Gcc-patches <
gcc-patches@gcc.gnu.org> wrote:

> If there are no further concerns, could a C++ or libcpp maintainer
> please commit this for me?
>
> Thank you!
>
> Tom.
>
> On 8/4/22 12:42 PM, Tom Honermann via Gcc-patches wrote:
> > Are there any further concerns with this patch? If not, I extend my
> > gratitude to anyone so kind as to commit this for me as I don't have
> > commit access.
> >
> > I just noticed that I neglected to add a ChangeLog entry for the
> > comment addition to gcc/cp/parser.cc. Noted inline below. I can
> > re-send the patch with that update if desired.
> >
> > Tom.
> >
> > On 8/1/22 2:49 PM, Tom Honermann wrote:
> >> Gcc's '#pragma GCC diagnostic' directives are processed in "early mode"
> >> (see handle_pragma_diagnostic_early) for the C++ frontend and, as such,
> >> require that the target diagnostic option be enabled for the
> >> preprocessor
> >> (see c_option_is_from_cpp_diagnostics).  This change modifies the
> >> -Wc++20-compat option definition to register it as a preprocessor option
> >> so that its associated diagnostics can be suppressed.  The changes also
> >> implicitly disable the option in C++20 and later modes.  These changes
> >> are consistent with the definition of the -Wc++11-compat option.
> >>
> >> This support is motivated by the need to suppress the following
> >> diagnostic
> >> otherwise issued in C++17 and earlier modes due to the char8_t typedef
> >> present in the uchar.h header file in glibc 2.36.
> >>    warning: identifier ‘char8_t’ is a keyword in C++20 [-Wc++20-compat]
> >>
> >> Tests are added to validate suppression of both -Wc++11-compat and
> >> -Wc++20-compat related diagnostics (fixes were only needed for the C++20
> >> case).
> >>
> >> Fixeshttps://gcc.gnu.org/PR106423.
> >>
> >> gcc/c-family/ChangeLog:
> >>     * c-opts.cc (c_common_post_options): Disable -Wc++20-compat
> >> diagnostics
> >>     in C++20 and later.
> >>     * c.opt (Wc++20-compat): Enable hooks for the preprocessor.
> >
> > gcc/cp/ChangeLog:
> >     * parser.cc (cp_lexer_saving_tokens): Add comment regarding
> > diagnostic requirements.
> >
> >>
> >> gcc/testsuite/ChangeLog:
> >>     * g++.dg/cpp0x/keywords2.C: New test.
> >>     * g++.dg/cpp2a/keywords2.C: New test.
> >>
> >> libcpp/ChangeLog:
> >>     * include/cpplib.h (cpp_warning_reason): Add CPP_W_CXX20_COMPAT.
> >>     * init.cc (cpp_create_reader): Add cpp_warn_cxx20_compat.
> >> ---
> >>   gcc/c-family/c-opts.cc                 |  7 +++++++
> >>   gcc/c-family/c.opt                     |  2 +-
> >>   gcc/cp/parser.cc                       |  5 ++++-
> >>   gcc/testsuite/g++.dg/cpp0x/keywords2.C | 16 ++++++++++++++++
> >>   gcc/testsuite/g++.dg/cpp2a/keywords2.C | 13 +++++++++++++
> >>   libcpp/include/cpplib.h                |  4 ++++
> >>   libcpp/init.cc                         |  1 +
> >>   7 files changed, 46 insertions(+), 2 deletions(-)
> >>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/keywords2.C
> >>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/keywords2.C
> >>
> >> diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
> >> index b9f01a65ed7..1ea37ba9742 100644
> >> --- a/gcc/c-family/c-opts.cc
> >> +++ b/gcc/c-family/c-opts.cc
> >> @@ -1046,6 +1046,13 @@ c_common_post_options (const char **pfilename)
> >>     else if (warn_narrowing == -1)
> >>       warn_narrowing = 0;
> >>   +  if (cxx_dialect >= cxx20)
> >> +    {
> >> +      /* Don't warn about C++20 compatibility changes in C++20 or
> >> later.  */
> >> +      warn_cxx20_compat = 0;
> >> +      cpp_opts->cpp_warn_cxx20_compat = 0;
> >> +    }
> >> +
> >>     /* C++17 has stricter evaluation order requirements; let's use
> >> some of them
> >>        for earlier C++ as well, so chaining works as expected. */
> >>     if (c_dialect_cxx ()
> >> diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> >> index 44e1a60ce24..dfdebd596ef 100644
> >> --- a/gcc/c-family/c.opt
> >> +++ b/gcc/c-family/c.opt
> >> @@ -455,7 +455,7 @@ Wc++2a-compat
> >>   C++ ObjC++ Warning Alias(Wc++20-compat) Undocumented
> >>     Wc++20-compat
> >> -C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++
> >> ObjC++,Wall)
> >> +C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++
> >> ObjC++,Wall) Init(0) CPP(cpp_warn_cxx20_compat)
> >> CppReason(CPP_W_CXX20_COMPAT)
> >>   Warn about C++ constructs whose meaning differs between ISO C++
> >> 2017 and ISO C++ 2020.
> >>     Wc++11-extensions
> >> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> >> index 4f67441eeb1..c3584446827 100644
> >> --- a/gcc/cp/parser.cc
> >> +++ b/gcc/cp/parser.cc
> >> @@ -924,7 +924,10 @@ cp_lexer_saving_tokens (const cp_lexer* lexer)
> >>   /* Store the next token from the preprocessor in *TOKEN. Return true
> >>      if we reach EOF.  If LEXER is NULL, assume we are handling an
> >>      initial #pragma pch_preprocess, and thus want the lexer to return
> >> -   processed strings.  */
> >> +   processed strings.
> >> +
> >> +   Diagnostics issued from this function must have their controlling
> >> option (if
> >> +   any) in c.opt annotated as a libcpp option via the CppReason
> >> property.  */
> >>     static void
> >>   cp_lexer_get_preprocessor_token (unsigned flags, cp_token *token)
> >> diff --git a/gcc/testsuite/g++.dg/cpp0x/keywords2.C
> >> b/gcc/testsuite/g++.dg/cpp0x/keywords2.C
> >> new file mode 100644
> >> index 00000000000..d67d01e31ed
> >> --- /dev/null
> >> +++ b/gcc/testsuite/g++.dg/cpp0x/keywords2.C
> >> @@ -0,0 +1,16 @@
> >> +// { dg-do compile { target c++98_only } }
> >> +// { dg-options "-Wc++11-compat" }
> >> +
> >> +// Validate suppression of -Wc++11-compat diagnostics.
> >> +#pragma GCC diagnostic ignored "-Wc++11-compat"
> >> +int alignof;
> >> +int alignas;
> >> +int constexpr;
> >> +int decltype;
> >> +int noexcept;
> >> +int nullptr;
> >> +int static_assert;
> >> +int thread_local;
> >> +int _Alignas;
> >> +int _Alignof;
> >> +int _Thread_local;
> >> diff --git a/gcc/testsuite/g++.dg/cpp2a/keywords2.C
> >> b/gcc/testsuite/g++.dg/cpp2a/keywords2.C
> >> new file mode 100644
> >> index 00000000000..8714a7b26b7
> >> --- /dev/null
> >> +++ b/gcc/testsuite/g++.dg/cpp2a/keywords2.C
> >> @@ -0,0 +1,13 @@
> >> +// { dg-do compile { target c++17_down } }
> >> +// { dg-options "-Wc++20-compat" }
> >> +
> >> +// Validate suppression of -Wc++20-compat diagnostics.
> >> +#pragma GCC diagnostic ignored "-Wc++20-compat"
> >> +int constinit;
> >> +int consteval;
> >> +int requires;
> >> +int concept;
> >> +int co_await;
> >> +int co_yield;
> >> +int co_return;
> >> +int char8_t;
> >> diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
> >> index 3eba6f74b57..9d90c18e4f2 100644
> >> --- a/libcpp/include/cpplib.h
> >> +++ b/libcpp/include/cpplib.h
> >> @@ -547,6 +547,9 @@ struct cpp_options
> >>     /* True if warn about differences between C++98 and C++11. */
> >>     bool cpp_warn_cxx11_compat;
> >>   +  /* True if warn about differences between C++17 and C++20. */
> >> +  bool cpp_warn_cxx20_compat;
> >> +
> >>     /* Nonzero if bidirectional control characters checking is on.
> >> See enum
> >>        cpp_bidirectional_level.  */
> >>     unsigned char cpp_warn_bidirectional;
> >> @@ -655,6 +658,7 @@ enum cpp_warning_reason {
> >>     CPP_W_C90_C99_COMPAT,
> >>     CPP_W_C11_C2X_COMPAT,
> >>     CPP_W_CXX11_COMPAT,
> >> +  CPP_W_CXX20_COMPAT,
> >>     CPP_W_EXPANSION_TO_DEFINED,
> >>     CPP_W_BIDIRECTIONAL
> >>   };
> >> diff --git a/libcpp/init.cc b/libcpp/init.cc
> >> index f4ab83d2145..cca3c1dc1e7 100644
> >> --- a/libcpp/init.cc
> >> +++ b/libcpp/init.cc
> >> @@ -202,6 +202,7 @@ cpp_create_reader (enum c_lang lang,
> >> cpp_hash_table *table,
> >>     CPP_OPTION (pfile, cpp_warn_c90_c99_compat) = -1;
> >>     CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) = -1;
> >>     CPP_OPTION (pfile, cpp_warn_cxx11_compat) = 0;
> >> +  CPP_OPTION (pfile, cpp_warn_cxx20_compat) = 0;
> >>     CPP_OPTION (pfile, cpp_warn_deprecated) = 1;
> >>     CPP_OPTION (pfile, cpp_warn_long_long) = 0;
> >>     CPP_OPTION (pfile, dollars_in_ident) = 1;
>
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-08-12  0:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-24  4:39 [PATCH 0/1] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics Tom Honermann
2022-07-24  4:39 ` [PATCH 1/1] " Tom Honermann
2022-07-27 23:09   ` Joseph Myers
2022-07-30 23:05     ` Tom Honermann
2022-07-31 15:05       ` Lewis Hyatt
2022-07-31 21:41         ` Tom Honermann
2022-08-01 18:49   ` [PATCH 1/1 v2] " Tom Honermann
2022-08-04 16:42     ` Tom Honermann
2022-08-11 22:44       ` Tom Honermann
2022-08-11 23:59         ` 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).