From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 5D1103948A5C for ; Wed, 16 Nov 2022 00:26:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5D1103948A5C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668558377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EMQ8tLypb5ZC72GG/ZXrW52YtAOJPcVtYM+WpM2TToU=; b=LEzgtjpsLf2stsxs3e0cw9M2rO3GFiF3nMiSsMMhJaUH7A+XCfntP4BAUOuQad/PH+My/7 PAACydXnx7+D9AvOMZmB4f0qe9Hk8+ehjiM+4g1b4bGUXm1MVbQ1hJNWrF6kuRlzVbs7p9 YZ2LnDkHpT78pBYSmWQy3Sajsi1jp54= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-302-IHRDpHDiONWFuLqF5m1oyA-1; Tue, 15 Nov 2022 19:26:15 -0500 X-MC-Unique: IHRDpHDiONWFuLqF5m1oyA-1 Received: by mail-ed1-f72.google.com with SMTP id q13-20020a056402518d00b00462b0599644so11264415edd.20 for ; Tue, 15 Nov 2022 16:26:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EMQ8tLypb5ZC72GG/ZXrW52YtAOJPcVtYM+WpM2TToU=; b=rVklp8D4ACJu2uCb+h3pRdm9YuxfbTDHJ/KfxSopQIKBVdAnBllsHtgzUeS2+2Y86o +psAPFHRKNoO33M0dAvjX5km9yu/8m4jgsH73tx/pur/GkbMSCut0KgWhDtOTZEq1HFn d88+AOpcoyE7tBpWZaGKERYlInkPoVpTUU+432SiUX+EUR4dnyEJgGp2hYUIb7mIL2fF EnHVcJEw+h/MMJbI+xiF0tp0NeNAf5RUhrPYbfNy2ywx+6m6SCJQLAOcPtlBKxTs42f/ QruTvIMuz8nWuKbCwP5/PcJvL8bjmKCX3Kax9Dlqtk1sifM6zAGlKZE43K+tgT0QEsDw GeHw== X-Gm-Message-State: ANoB5pnovZgNjPIusA9basyTqxuimUmLcRP6doQvl8gdIZG1EYoV6mZ3 OX63JiJ5AifeBVlduRL/vHeHVFvMANwBDw8L0iDcYVAgWFNQQ+L2dE5BzUWtCz93aheRRz8yKbL wvAPgbSSzsAt7QOzLs6fmTrjYpY7+/MbjwA== X-Received: by 2002:a17:906:1ed0:b0:78d:9e77:1f8c with SMTP id m16-20020a1709061ed000b0078d9e771f8cmr15751788ejj.236.1668558374804; Tue, 15 Nov 2022 16:26:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ixGncXkRtPTXOkBo9yQ+jMU8J0Yk1kUu2QmUreJQbr9JVjbf+hUtlY/S8kEiJ2f8kIZ9Ta9XghnarKjKxh24= X-Received: by 2002:a17:906:1ed0:b0:78d:9e77:1f8c with SMTP id m16-20020a1709061ed000b0078d9e771f8cmr15751773ejj.236.1668558374551; Tue, 15 Nov 2022 16:26:14 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Wed, 16 Nov 2022 00:26:03 +0000 Message-ID: Subject: Re: [PATCH] c++, v2: Implement C++23 P2647R1 - Permitting static constexpr variables in constexpr functions To: Jason Merrill Cc: Jakub Jelinek , gcc-patches@gcc.gnu.org, Marek Polacek X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.2 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 List-Id: On Tue, 15 Nov 2022 at 23:36, Jason Merrill wrote: > > On 11/13/22 01:45, Jakub Jelinek wrote: > > 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. > > This was accepted as a DR, so it shouldn't be limited to C++23 mode. > Certainly it should be allowed in C++20 mode; I don't have a strong > opinion about C++14/17. Jonathan, do you? I don't. The lack of this feature caused some awkwardness implementing a C++23 library feature in , but that means my desire for it was only in C++23 mode. And that has been mitigated by changes Patrick made to work around it anyway. I think it does make sense for C++20, where constexpr is pretty close to "normal" code, what with dynamic allocations, std::string etc. but I don't see a great need for it before C++20. > > > (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. > > > > --- 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; > > > > > > Jakub > > >