Bug 102612 - [C++23] P2242R3 - Non-literal variables (and labels and gotos) in constexpr functions
Summary: [C++23] P2242R3 - Non-literal variables (and labels and gotos) in constexpr f...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks: c++23-core
  Show dependency treegraph
 
Reported: 2021-10-05 16:24 UTC by Marek Polacek
Modified: 2021-10-06 09:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-10-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2021-10-05 16:24:56 UTC
See https://wg21.link/p2242r3
Comment 1 Marek Polacek 2021-10-05 16:26:29 UTC
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2021-October/580960.html
Comment 2 GCC Commits 2021-10-06 08:30:10 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:8892d532d66910e518bc135a851a104322385ca2

commit r12-4206-g8892d532d66910e518bc135a851a104322385ca2
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Oct 6 10:28:31 2021 +0200

    c++: Implement C++23 P2242R3 - Non-literal variables (and labels and gotos) in constexpr functions [PR102612]
    
    The following patch implements C++23 P2242R3 - Non-literal variables
    (and labels and gotos) in constexpr functions.
    I think it is mostly straightforward, don't diagnose certain
    statements/declarations just because of their presence in
    constexpr/consteval functions, but (except for the non-literal type
    var declarations which ought to be caught by e.g. constructor or
    destructor call during evaluation not being constexpr and for
    labels which are now always allowed) diagnose it during constexpr
    evaluation.
    
    2021-10-06  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/102612
    gcc/c-family/
            * c-cppbuiltin.c (c_cpp_builtins): For -std=c++23 predefine
            __cpp_constexpr to 202110L rather than 201907L.
    gcc/cp/
            * parser.c (cp_parser_jump_statement): Implement C++23 P2242R3.
            Allow goto expressions in constexpr function bodies for C++23.
            Adjust error message for older standards to mention it.
            * decl.c (start_decl): Allow static and thread_local declarations
            in constexpr function bodies for C++23.  Adjust error message for
            older standards to mention it.
            * constexpr.c (ensure_literal_type_for_constexpr_object): Allow
            declarations of variables with non-literal type in constexpr function
            bodies for C++23.  Adjust error message for older standards to mention
            it.
            (cxx_eval_constant_expression) <case DECL_EXPR>: Diagnose declarations
            of initialization of static or thread_local vars.
            (cxx_eval_constant_expression) <case GOTO_EXPR>: Diagnose goto
            statements for C++23.
            (potential_constant_expression_1) <case DECL_EXPR>: Swap the
            CP_DECL_THREAD_LOCAL_P and TREE_STATIC checks.
            (potential_constant_expression_1) <case LABEL_EXPR>: Allow labels for
            C++23.  Adjust error message for older standards to mention it.
    gcc/testsuite/
            * g++.dg/cpp23/feat-cxx2b.C: Expect __cpp_constexpr 202110L rather
            than 201907L.
            * g++.dg/cpp23/constexpr-nonlit1.C: New test.
            * g++.dg/cpp23/constexpr-nonlit2.C: New test.
            * g++.dg/cpp23/constexpr-nonlit3.C: New test.
            * g++.dg/cpp23/constexpr-nonlit4.C: New test.
            * g++.dg/cpp23/constexpr-nonlit5.C: New test.
            * g++.dg/cpp23/constexpr-nonlit6.C: New test.
            * g++.dg/diagnostic/constexpr1.C: Only expect some diagnostics for
            c++20_down.
            * g++.dg/cpp1y/constexpr-label.C: Likewise.
            * g++.dg/cpp1y/constexpr-neg1.C: Likewise.
            * g++.dg/cpp2a/constexpr-try5.C: Likewise.  Adjust some expected
            wording.
            * g++.dg/cpp2a/constexpr-dtor3.C: Likewise.
            * g++.dg/cpp2a/consteval3.C: Likewise.  Add effective target c++20
            and remove dg-options.
Comment 3 Jakub Jelinek 2021-10-06 09:12:04 UTC
Implemented for GCC 12.