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

            Bug ID: 116015
           Summary: ICE in replace_placeholders_r for simple default
                    member initializer
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pieter.p.dev at outlook dot com
  Target Milestone: ---

Created attachment 58713
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58713&action=edit
Output from -freport-bug

G++ crashes when using member variables in the default initializer for another
member. Minimal example:

    struct MatrixLayout {
        int rows         = 0;
        int outer_stride = rows;
    };
    struct Matrix {
        Matrix(MatrixLayout) {}
    };
    struct Widget {
        int n = 5;
        Matrix A{{.rows = n}};
    };
    int main() {
        Widget w{};
    }

All versions of GCC between at least 5.1 and 14.1 seem to be affected:
  - 5.1: https://godbolt.org/z/1PKx8djxG
  - 14.1: https://godbolt.org/z/1eeEcYoqd
  - trunk: https://godbolt.org/z/7j7n38ohh
(8d6498f0d772775ad09d7d9e14f491a306e5f853)

Possibly related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100252#c5.

To the best of my knowledge, the source code is valid C++20 (and valid C++11
without the designated initializer), and Clang and MSVC compile the same code
without issues.

Output from GCC 14.1:

    ice.cpp: In function 'int main()':
    ice.cpp:16:14: internal compiler error: in replace_placeholders_r, at
cp/tree.cc:3414
       16 |     Widget w{};
          |              ^
    0x732cae replace_placeholders_r
        cp/tree.cc:3414
    0x11be9e3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*,
void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        tree.cc:11429
    0x11bef2f walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*,
void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        tree.cc:11663
    0x960b0c replace_placeholders_r
        cp/tree.cc:3459
    0x11be9e3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*,
void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        tree.cc:11429
    0x95d985 replace_placeholders(tree_node*, tree_node*, bool*)
        cp/tree.cc:3497
    0x7e0dde cp_gimplify_init_expr
        cp/cp-gimplify.cc:339
    0x7e0dde cp_gimplify_expr(tree_node**, gimple**, gimple**)
        cp/cp-gimplify.cc:652
    0xc139b8 gimplify_expr(tree_node**, gimple**, gimple**, bool
(*)(tree_node*), int)
        gimplify.cc:17790
    0xc17616 gimplify_stmt(tree_node**, gimple**)
        gimplify.cc:7578
    0xc19632 gimplify_and_add(tree_node*, gimple**)
        gimplify.cc:515
    0xc19632 internal_get_tmp_var
        gimplify.cc:674
    0xc13c7b gimplify_expr(tree_node**, gimple**, gimple**, bool
(*)(tree_node*), int)
        gimplify.cc:18908
    0xc1b564 gimplify_expr
        gimplify.cc:18953
    0xc1b564 gimplify_arg(tree_node**, gimple**, unsigned int, bool)
        gimplify.cc:3779
    0xc1da17 gimplify_call_expr
        gimplify.cc:4064
    0xc15ac2 gimplify_expr(tree_node**, gimple**, gimple**, bool
(*)(tree_node*), int)
        gimplify.cc:17853
    0xc17616 gimplify_stmt(tree_node**, gimple**)
        gimplify.cc:7578
    0xc15607 gimplify_cleanup_point_expr
        gimplify.cc:7316
    0xc15607 gimplify_expr(tree_node**, gimple**, gimple**, bool
(*)(tree_node*), int)
        gimplify.cc:18277

Reply via email to