Message ID | 20220801184900.1326396-1-tom@honermann.net |
---|---|
State | New, archived |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp2511591pxt; Mon, 1 Aug 2022 11:49:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vNPYpyJhWesb+SHE4hMU0Bnf7U5NIJLQ9iXAWPxuC3WZzpSkmO48fVxndGJNBS/jheIIC/ X-Received: by 2002:a17:907:7245:b0:72f:39e7:1207 with SMTP id ds5-20020a170907724500b0072f39e71207mr13588489ejc.201.1659379791720; Mon, 01 Aug 2022 11:49:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659379791; cv=none; d=google.com; s=arc-20160816; b=NPz53rTzUQHjK2Aov+6qf2olSNBNiOuaCLt5zjLXZ2sVoFtRSDXXucUX09bqBErNsq AylBiZm5kDp5QhDv1dHrmUMPBW83NaGCibs1gy+3ixQd8j2w1+WZ41Gft/0yMHwQYQSO dAyvA57ufzd62+7ec87w87mzRhk7XukOGOvW7AIBvgRJeRjWOadliLZxzyKGSQ2jlqkD 52m9CJRKj9IOInY0IHgRbJ/cjHjHjYY6yWok8BoZ3owmp8K6n439OqSrjYZijgN5S55Q ok8u2i9e+DSoTdoKk3amkZ9zQMBDXWbASQnrOaHVE5sErzuWQ/KL9KQpGewBaIj3kLKN XUsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=iRhyc1CjOp7J4w+1rfXQt0RMal08vr/S8tK7q4juOYs=; b=lNHupjYz6u7MNlgaYkGo3ZfdqRiKzvK8IMHYgj7csqsAswIv267dX6ipoihEFznWG1 EUjC9EAO9m40TV4uEiYMlfP/9eREqtshHnps/Q1WhSAsUMEv6c9Uod8xMfe6s6OsX3WM Zf34z+Bj/zIqB+J697iufXGhCqtH/zuc+j7mX8ct6jQEz6xQOIKQZZr/mqGczOs1eEBO BFx2tCj+zwdWKTG6CmBEijgonuwwQv9beVW+lYG4Us6TQqXOIpaMuLJmj7yJJmEX2GGX Dynf9G+HKANpyaC9LmnRud3Rwf8KiehOSY8ZbWotIAxtF/SxudvaVmcKGY7j1WVUNf9n igng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="UxAD+/Ig"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cr14-20020a170906d54e00b00722d5b8794dsi11237368ejc.308.2022.08.01.11.49.51 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 11:49:51 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="UxAD+/Ig"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71BC53858000 for <ouuuleilei@gmail.com>; Mon, 1 Aug 2022 18:49:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71BC53858000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1659379790; bh=iRhyc1CjOp7J4w+1rfXQt0RMal08vr/S8tK7q4juOYs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=UxAD+/IgEfDoRNR72u+4GVJm4prHLtlHJ4KXXZ4DQf4oQoOnf4UVHweaiB21UC8ta /g0L64Dmv6M+mmfE7T7qZb886uEomCG7ZiBl7+l4ZFQU+/OwUnSGOAPadidmkEeyT6 4/Xj4+gNdJNIrwhr+iIjqweavbjof3SG/teeAgPU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp127.iad3b.emailsrvr.com (smtp127.iad3b.emailsrvr.com [146.20.161.127]) by sourceware.org (Postfix) with ESMTPS id 6046C385842E for <gcc-patches@gcc.gnu.org>; Mon, 1 Aug 2022 18:49:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6046C385842E X-Auth-ID: tom@honermann.net Received: by smtp8.relay.iad3b.emailsrvr.com (Authenticated sender: tom-AT-honermann.net) with ESMTPSA id F2E524015F; Mon, 1 Aug 2022 14:49:05 -0400 (EDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/1 v2] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics. Date: Mon, 1 Aug 2022 14:49:00 -0400 Message-Id: <20220801184900.1326396-1-tom@honermann.net> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220724043902.1777378-2-tom@honermann.net> References: <20220724043902.1777378-2-tom@honermann.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Classification-ID: e7526e11-0ef7-462b-8285-687f985a657e-1-1 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Tom Honermann via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Tom Honermann <tom@honermann.net> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1739207648857641536?= X-GMAIL-MSGID: =?utf-8?q?1739985824352795382?= |
Series |
[1/1,v2] c++/106423: Fix pragma suppression of -Wc++20-compat diagnostics.
|
|
Commit Message
Tom Honermann
Aug. 1, 2022, 6:49 p.m. UTC
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
Comments
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;
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;
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; > >
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;