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

--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>:

https://gcc.gnu.org/g:0d97700443b45b947eda40dac7cf4d0397770b87

commit r15-7306-g0d97700443b45b947eda40dac7cf4d0397770b87
Author: Marek Polacek <pola...@redhat.com>
Date:   Mon Jan 27 14:23:22 2025 -0500

    c++: wrong-code with consteval constructor [PR117501]

    We've had a wrong-code problem since r14-4140, due to which we
    forget to initialize a variable.

    In consteval39.C, we evaluate

        struct QQQ q;
      <<cleanup_point <<< Unknown tree: expr_stmt
        QQQ::QQQ (&q, TARGET_EXPR <D.2687, <<< Unknown tree: aggr_init_expr
          5
          __ct_comp
          D.2687
          (struct basic_string_view *) <<< Unknown tree: void_cst >>>
          (const char *) "" >>>>) >>>>>;

    into

        struct QQQ q;
      <<cleanup_point <<< Unknown tree: expr_stmt
        {.data={._M_len=42, ._M_str=0}} >>>>>;

    and then the useless expr_stmt is dropped on the floor, so q isn't
    initialized.  As pre-r14-4140, we need to handle constructors specially.

    With this patch, we generate:

        struct QQQ q;
      <<cleanup_point <<< Unknown tree: expr_stmt
        q = {.data={._M_len=42, ._M_str=0}} >>>>>;

    initializing q properly.

            PR c++/117501

    gcc/cp/ChangeLog:

            * cp-gimplify.cc (cp_build_init_expr_for_ctor): New.
            (cp_fold_immediate_r): Call it.
            (cp_fold): Break out code into cp_build_init_expr_for_ctor.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/consteval39.C: New test.
            * g++.dg/cpp2a/consteval40.C: New test.

    Reviewed-by: Jason Merrill <ja...@redhat.com>

Reply via email to