diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 37ea65cb655..497f64f3cea 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -9316,7 +9316,8 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant, if (TREE_CODE (t) == TARGET_EXPR && TARGET_EXPR_INITIAL (t) == r) return t; - else if (TREE_CODE (t) == CONSTRUCTOR || TREE_CODE (t) == CALL_EXPR) + else if (TREE_CODE (t) == CONSTRUCTOR || TREE_CODE (t) == CALL_EXPR + || TREE_CODE (t) == AGGR_INIT_EXPR) /* Don't add a TARGET_EXPR if our argument didn't have one. */; else if (TREE_CODE (t) == TARGET_EXPR && TARGET_EXPR_CLEANUP (t)) r = get_target_expr (r); diff --git a/gcc/testsuite/g++.dg/cpp2a/constinit20.C b/gcc/testsuite/g++.dg/cpp2a/constinit20.C new file mode 100644 index 00000000000..9b043917dc3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constinit20.C @@ -0,0 +1,18 @@ +// PR c++/119652 +// { dg-do compile { target c++20 } } + +struct __shared_count { + constexpr __shared_count() {} + ~__shared_count(); + int _M_pi = 0; +}; +struct shared_ptr { + __shared_count _M_refcount; +}; +struct A { + A() = default; + shared_ptr m; +}; +constinit A a; +constinit A b {}; +constinit A c = {};