-
- Downloads
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 <jason@redhat.com>
Loading
Please register or sign in to comment