diff options
author | Marek Polacek <polacek@redhat.com> | 2025-01-07 10:15:42 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2025-01-08 09:27:45 -0500 |
commit | 68da968e46e7603a4c11099a6c8dd5ad24e4f43e (patch) | |
tree | 01a5bdec57fb63e0bfa5be399ce4bfcc7028282b | |
parent | 84e90b69fba1cfa2a77942251ddfd0527fb22811 (diff) | |
download | gcc-68da968e46e7603a4c11099a6c8dd5ad24e4f43e.zip gcc-68da968e46e7603a4c11099a6c8dd5ad24e4f43e.tar.gz gcc-68da968e46e7603a4c11099a6c8dd5ad24e4f43e.tar.bz2 |
c++: ICE with MODIFY_EXPR in constexpr [PR118169]
Here, cxx_eval_outermost_expression gets a sequence of initialization
statements:
D.2912.t = TARGET_EXPR <...>;
TARGET_EXPR <D.2922, 1>;
D.2922 = 0;
the last of which wasn't converted to void and so we, since r15-6369,
do not take the "if (VOID_TYPE_P (type))" path, and try to set
D.2912 to false.
The last statement comes from build_disable_temp_cleanup.
convert_to_void is typically called from finish_expr_stmt, but we are
adding the cleanup statement via add_stmt which doesn't convert to void.
So I think we can use finish_expr_stmt instead.
PR c++/118169
gcc/cp/ChangeLog:
* typeck2.cc (split_nonconstant_init): Call finish_expr_stmt instead
of add_stmt.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/constexpr-prvalue2.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
-rw-r--r-- | gcc/cp/typeck2.cc | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/constexpr-prvalue2.C | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc index 381f198..5dae7fc 100644 --- a/gcc/cp/typeck2.cc +++ b/gcc/cp/typeck2.cc @@ -757,7 +757,7 @@ split_nonconstant_init (tree dest, tree init) init = NULL_TREE; for (tree f : flags) - add_stmt (build_disable_temp_cleanup (f)); + finish_expr_stmt (build_disable_temp_cleanup (f)); release_tree_vector (flags); code = pop_stmt_list (code); diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-prvalue2.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-prvalue2.C new file mode 100644 index 0000000..7076c65 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-prvalue2.C @@ -0,0 +1,13 @@ +// PR c++/118169 +// { dg-do compile { target c++14 } } +// { dg-options "-O" } + +struct A { constexpr A (int *x) : s(x) {} ~A (); int *s; }; +struct B { A t; int u = 0; }; +void foo (B &&); + +void +bar (int &x) +{ + foo ({ &x }); +} |