From patchwork Sun Nov 13 11:45:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 19351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1645816wru; Sun, 13 Nov 2022 03:46:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf7MClHbkBTRYUTvxGdkzpAhQ8cPlVEQn90YLR2sLJUAXSEimyuTsPQ7F1gOg2SWDKlo6ERV X-Received: by 2002:a17:906:b14f:b0:7ad:90db:c241 with SMTP id bt15-20020a170906b14f00b007ad90dbc241mr7344108ejb.284.1668339978946; Sun, 13 Nov 2022 03:46:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668339978; cv=none; d=google.com; s=arc-20160816; b=w21nq5kqJbYipCfE5kilo7T7Lz/9AAeoCqKuQVS9902DuPD7MN0H18EBbYIdggMWoG Dp33RuVU2TSp+mfuTcOzi6XIB3ZO867YG+sRcBT1gz9ISZX353DUiCS9r7lSuw8tta4o /ExQWM5KQwvx6qGPebmytCBvt2PHwdaH5Q/5YwHyqgemfoF78rxeUa9k4bPKbmN8JBEs JyFVt4J655VjabvsBwBozqW0g9PiMa0sstkpp4sMc9e908AGPpEBOMR7UsmkDeOeHE6B kovCBzZZeaZJNgO37U5LZSyFFclDIoAlWU4H/qb2F3WyKrBLzbTiDloJufjhXrRMoh3B v0lQ== 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-disposition:in-reply-to:mime-version:references:message-id :subject:cc:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=jaViw9wJ9ChAyshgyUsz4JVrWQnX+p5MMS8+pLsl8hw=; b=dsWjXsZgqdwOZZPZz5cbhhh7b811Y3Ph9CH9rnYpTVqDSK6snLxl3heuIvDBl4JuSF Qrx/jKruV6QF11qVP6Q/IV27wm6MzAvalXMau8Dy30U0r4b4rYt+jHP1254IH1OJSL6k Tmq2qxnoFEqPxoCS0oaEpKcGN5BpvbFwx+4HF1A1RndU761Lw50dvq2xWNcYBr3joLP/ DvAjX4bCfct1i7unN5yMV+3hlhHus1eCw3p59l4OrmzflzKQv6BwfoGNeO260ykgf4Mu z41sz0aLw2UA3GfG33Cgjjr7AUACVNTKhShExD2Juo/gfVnTGt1uD0PbgfOlROVTLDsw H4pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=r8xQ89hE; 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 ec34-20020a0564020d6200b00461ace746adsi5736945edb.453.2022.11.13.03.46.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Nov 2022 03:46:18 -0800 (PST) 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=r8xQ89hE; 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 BBE533858436 for ; Sun, 13 Nov 2022 11:46:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBE533858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668339977; bh=jaViw9wJ9ChAyshgyUsz4JVrWQnX+p5MMS8+pLsl8hw=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=r8xQ89hEcAny0PFIGwVeD1A511fSUdGo32gxiBYnY5qKYJBXXeTJ2jncx5l1L0JJR lG3uV05fC2sd5PvVmBK55P62NCCcBdraz2K34ArbjYITTzMAqvPIckGWe1vn/J83e9 RHkatBtq5y9wItjp+ftQwLD+Eh2qHG0Th0F2Zd8Q= 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 1648E3858436 for ; Sun, 13 Nov 2022 11:45:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1648E3858436 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-412-LdOcXFi-PWyl9zzdS3uqWg-1; Sun, 13 Nov 2022 06:45:14 -0500 X-MC-Unique: LdOcXFi-PWyl9zzdS3uqWg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11C7C101A528 for ; Sun, 13 Nov 2022 11:45:14 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BDF47111F3DF; Sun, 13 Nov 2022 11:45:13 +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 2ADBj9xB2801383 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 13 Nov 2022 12:45:09 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2ADBj9jP2801382; Sun, 13 Nov 2022 12:45:09 +0100 Date: Sun, 13 Nov 2022 12:45:08 +0100 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, Marek Polacek Subject: [PATCH] c++, v2: Implement C++23 P2647R1 - Permitting static constexpr variables in constexpr functions Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 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 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?1749381261866975041?= X-GMAIL-MSGID: =?utf-8?q?1749381261866975041?= On Fri, Nov 11, 2022 at 06:07:04PM +0100, Jakub Jelinek wrote: > The following patch on top of Marek's P2448 PR106649 patch > (mainly because that patch implements the previous __cpp_constexpr > feature test macro bump so this can't go in earlier; OT, > P2280R4 doesn't have any feature test macro?) implements this > simple paper. > > Ok for trunk if it passes bootstrap/regtest and is voted into C++23? Here is an updated patch that passed bootstrap/regtest, the only change is another testcase tweak. 2022-11-13 Jakub Jelinek gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Bump __cpp_constexpr value from 202207L to 202211L. gcc/cp/ * constexpr.cc (cxx_eval_constant_expression): Implement C++23 P2647R1 - Permitting static constexpr variables in constexpr functions. Allow decl_maybe_constant_var_p static or thread_local vars for C++23. (potential_constant_expression_1): Likewise. gcc/testsuite/ * g++.dg/cpp23/constexpr-nonlit17.C: New test. * g++.dg/cpp23/feat-cxx2b.C: Adjust expected __cpp_constexpr value. * g++.dg/ext/stmtexpr19.C: Don't expect an error for C++23 or later. Jakub --- gcc/c-family/c-cppbuiltin.cc.jj 2022-11-11 17:14:52.021613271 +0100 +++ gcc/c-family/c-cppbuiltin.cc 2022-11-11 17:17:45.065265246 +0100 @@ -1074,7 +1074,7 @@ c_cpp_builtins (cpp_reader *pfile) /* Set feature test macros for C++23. */ cpp_define (pfile, "__cpp_size_t_suffix=202011L"); cpp_define (pfile, "__cpp_if_consteval=202106L"); - cpp_define (pfile, "__cpp_constexpr=202207L"); + cpp_define (pfile, "__cpp_constexpr=202211L"); cpp_define (pfile, "__cpp_multidimensional_subscript=202110L"); cpp_define (pfile, "__cpp_named_character_escapes=202207L"); cpp_define (pfile, "__cpp_static_call_operator=202207L"); --- gcc/cp/constexpr.cc.jj 2022-11-11 17:14:52.024613231 +0100 +++ gcc/cp/constexpr.cc 2022-11-11 17:16:54.384952917 +0100 @@ -7085,7 +7085,8 @@ cxx_eval_constant_expression (const cons && (TREE_STATIC (r) || (CP_DECL_THREAD_LOCAL_P (r) && !DECL_REALLY_EXTERN (r))) /* Allow __FUNCTION__ etc. */ - && !DECL_ARTIFICIAL (r)) + && !DECL_ARTIFICIAL (r) + && (cxx_dialect < cxx23 || !decl_maybe_constant_var_p (r))) { if (!ctx->quiet) { @@ -9577,7 +9578,10 @@ potential_constant_expression_1 (tree t, tmp = DECL_EXPR_DECL (t); if (VAR_P (tmp) && !DECL_ARTIFICIAL (tmp)) { - if (CP_DECL_THREAD_LOCAL_P (tmp) && !DECL_REALLY_EXTERN (tmp)) + if (CP_DECL_THREAD_LOCAL_P (tmp) + && !DECL_REALLY_EXTERN (tmp) + && (cxx_dialect < cxx23 + || !decl_maybe_constant_var_p (tmp))) { if (flags & tf_error) constexpr_error (DECL_SOURCE_LOCATION (tmp), fundef_p, @@ -9585,7 +9589,9 @@ potential_constant_expression_1 (tree t, "% context", tmp); return false; } - else if (TREE_STATIC (tmp)) + else if (TREE_STATIC (tmp) + && (cxx_dialect < cxx23 + || !decl_maybe_constant_var_p (tmp))) { if (flags & tf_error) constexpr_error (DECL_SOURCE_LOCATION (tmp), fundef_p, --- gcc/testsuite/g++.dg/cpp23/constexpr-nonlit17.C.jj 2022-11-11 17:59:59.972852793 +0100 +++ gcc/testsuite/g++.dg/cpp23/constexpr-nonlit17.C 2022-11-11 17:59:38.725141231 +0100 @@ -0,0 +1,12 @@ +// P2647R1 - Permitting static constexpr variables in constexpr functions +// { dg-do compile { target c++23 } } + +constexpr char +test () +{ + static const int x = 5; + static constexpr char c[] = "Hello World"; + return *(c + x); +} + +static_assert (test () == ' '); --- gcc/testsuite/g++.dg/cpp23/feat-cxx2b.C.jj 2022-11-11 17:14:52.194610922 +0100 +++ gcc/testsuite/g++.dg/cpp23/feat-cxx2b.C 2022-11-11 17:48:56.038865825 +0100 @@ -134,8 +134,8 @@ #ifndef __cpp_constexpr # error "__cpp_constexpr" -#elif __cpp_constexpr != 202207 -# error "__cpp_constexpr != 202207" +#elif __cpp_constexpr != 202211 +# error "__cpp_constexpr != 202211" #endif #ifndef __cpp_decltype_auto --- gcc/testsuite/g++.dg/ext/stmtexpr19.C.jj 2020-01-14 20:02:46.839608995 +0100 +++ gcc/testsuite/g++.dg/ext/stmtexpr19.C 2022-11-12 09:17:40.706245495 +0100 @@ -8,7 +8,7 @@ const test* setup() { static constexpr test atest = { - ({ static const int inner = 123; &inner; }) // { dg-error "static" } + ({ static const int inner = 123; &inner; }) // { dg-error "static" "" { target c++20_down } } }; return &atest;