From patchwork Mon Aug 22 09:53:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 649 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp409343wro; Mon, 22 Aug 2022 02:54:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR4EA47DiLb2+w5pLiRaN5YjLXSQcSGGD+224OhvUy+MrVvXuKItp0DleYIs2hllSJ7RTGN8 X-Received: by 2002:aa7:c554:0:b0:445:fa29:b11a with SMTP id s20-20020aa7c554000000b00445fa29b11amr14937466edr.168.1661162065969; Mon, 22 Aug 2022 02:54:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661162065; cv=none; d=google.com; s=arc-20160816; b=aXJG36Bshs8v/namH3SB3Uj1R9sjiQT74/8Y6/jP3oHUk4EXoaNx+aNruZGg/EDBwc QwT3bTvT3dP+ZoVd2vBjqU8sWgaBQXC+v4xWvnQSh/KEGL54XSxbXjyLlaJGtpj3F4De qIIzHFElMbfSi1Eyo/KM9HF6xMjU1x3Cq3jzgXTf/oNsJUFQ85vpmCeECmJM/wlR5GSU VjrWcwI0VOFHVxzkrZnhRgltBQIvomI82coiZU+X6WuQNYMU30/uj5TymR+a/3hj255Q 8KCbEQXH7Az0tM3ds2AwO1+DT+ID9QhcDZAwOcJjsyIu6yqNJpwSRWEIJ6Ut3vFhV/0P CsSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:in-reply-to:mime-version:references:message-id :subject:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=tcYVf6XztXp2Ja4UfNMSvmxHMkTN9Jo5/Pjr6LJJK4Y=; b=YCPnAGHR55th9ENWpCnXP1H1BesACVIX1xEjYhmbgbYFWPm2Zwkuv087G+2XrtfDCQ zmfDKDrvRmR/av62bPCxuoaUvuIe/dBn5GsjZL0SMLO7340OkRLm76uxxF6lnAvdQbUk ie3zV/PXRy1G9xRlu1/NZ+mJqoiCyHUJ/G2v8YHWE3/4oJSO++MnHGOf0Zld9myZCcl4 Lieiu5u8HfnkrEdgwpyyMfGNEenIM3lL2IZJy4NZ0WyKOab1MfbF/8a3mgqzO1yZ/6A4 C1NR28mzzCakEvEp/iKmCYi43I8C9YPLYn/oy6+vzG1EXLRJSPss2pt9SMOM4EykJoGD uMEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=huQvhbQU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id sa1-20020a1709076d0100b0073d6b849d4fsi4539837ejc.731.2022.08.22.02.54.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 02:54:25 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=huQvhbQU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 AE7F038582B0 for ; Mon, 22 Aug 2022 09:54:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE7F038582B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661162064; bh=tcYVf6XztXp2Ja4UfNMSvmxHMkTN9Jo5/Pjr6LJJK4Y=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=huQvhbQUQqdvpsCZw/mxeWfKb3aI2I6ZjPh/AVuQlCpTdnEVZEWeZd8RT/rozr8wz iBdL4mKUAnXrZw538forRtJNe6kzAg78kHxMQengG6WxeDx/2inTxFcVMHKx0LWYcU 85sys96H6RuueYmjUdCsCPla7sdxNRRT/w+MH0SY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2877C3858C20 for ; Mon, 22 Aug 2022 09:53:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2877C3858C20 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-572-_ncZ68IPO3uLcpps4IsAjg-1; Mon, 22 Aug 2022 05:53:38 -0400 X-MC-Unique: _ncZ68IPO3uLcpps4IsAjg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1FE1129ABA34; Mon, 22 Aug 2022 09:53:38 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C33E2166B29; Mon, 22 Aug 2022 09:53:37 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 27M9rYet2986874 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 22 Aug 2022 11:53:35 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 27M9rYs32986873; Mon, 22 Aug 2022 11:53:34 +0200 Date: Mon, 22 Aug 2022 11:53:33 +0200 To: Jason Merrill , Joseph Myers Subject: [PATCH] preprocessor: Implement C++23 P2437R1 - Support for #warning [PR106646] Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: Marek Polacek , gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1741854674449080580?= X-GMAIL-MSGID: =?utf-8?q?1741854674449080580?= 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 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. Jakub --- 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 }