https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125840

--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <[email protected]>:

https://gcc.gnu.org/g:826a52902ecef7cdda3bfe1e1cf10cd8eb49563b

commit r17-4187-g826a52902ecef7cdda3bfe1e1cf10cd8eb49563b
Author: Jakub Jelinek <[email protected]>
Date:   Sat Sep 12 09:56:25 2026 +0200

    c++: Implement C++26 CWG 3158 - const-ification of Splice Expressions
[PR125840]

    The paper claims that GCC already implements it, which is only partially
    the case.  Non-dependent splice expression of a variable (of function
    parameter or real variable) inside of contract conditions goes through
    finish_id_expression -> finish_id_expression_1 which calls
    constify_contract_access when needed.
    We don't call it during tsubst_splice_expr though (and the paper requires
    us to constify in that case), and on the other side, for splice expression
    of a reflection of an object we weren't distinguishing it from splice
    expression of a reflection of a variable.

    So, the following patch
    1) for splice wraps decls from REFLECT_OBJECT into a VCE, so that they
       still act as lvalues, but aren't considered the variables themselves,
       just an lvalue referencing them
    2) calls constify_contract_access during tsubst_splice_expr

    I've added all testcases from the paper (after fixing numerous bugs in
    those), plus related stuff I could come up with.

    2026-09-12  Jakub Jelinek  <[email protected]>

            P3598R0
            PR c++/125840
            * reflect.cc: Implement C++26 CWG 3158 - const-ification of Splice
            Expressions.
            (splice): Remember REFLECT_EXPR_KIND of REFLECT_EXPR.  Set refl to
            REFLECT_EXPR_HANDLE earlier.  For REFLECT_OBJECT wrap decls into
            a VCE to differentiate it from corresponding variables.
            * pt.cc (tsubst_splice_expr): Call constify_contract_access if
            needed.

            * g++.dg/reflect/contract1.C: New test.
            * g++.dg/reflect/contract2.C: New test.
            * g++.dg/reflect/contract3.C: New test.
            * g++.dg/reflect/contract4.C: New test.
            * g++.dg/reflect/contract5.C: New test.
            * g++.dg/reflect/reflect_object2.C (g): Add test for setting of
            splice expr of an object reflection.

    Reviewed-by: Jason Merrill <[email protected]>
  • [Bug c++/125840] [C++26] P3598R... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to