diff options
author | Jason Merrill <jason@redhat.com> | 2023-03-14 12:20:51 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2023-03-14 14:45:34 -0400 |
commit | 71b33f8fb8daa6a7a359f322b24365d9016438fc (patch) | |
tree | 56ec4d9930b6546b13386ae89ef2dfc083e540cd /gcc/cp | |
parent | 42630fadbe248717859d61c0244c821c32b4e52c (diff) | |
download | gcc-71b33f8fb8daa6a7a359f322b24365d9016438fc.zip gcc-71b33f8fb8daa6a7a359f322b24365d9016438fc.tar.gz gcc-71b33f8fb8daa6a7a359f322b24365d9016438fc.tar.bz2 |
c++: -Wreturn-type with if (true) throw [PR107310]
I removed this folding in GCC 12 because it was interfering with an
experiment of richi's, but that never went in and the change causes
regressions, so let's put it back.
This reverts commit r12-5638-ga3e75c1491cd2d.
PR c++/107310
gcc/cp/ChangeLog:
* cp-gimplify.cc (genericize_if_stmt): Restore folding
of constant conditions.
gcc/testsuite/ChangeLog:
* c-c++-common/Wimplicit-fallthrough-39.c: Adjust warning.
* g++.dg/warn/Wreturn-6.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/cp-gimplify.cc | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index b995b4f..4fecd56 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -190,6 +190,12 @@ genericize_if_stmt (tree *stmt_p) } else if (IF_STMT_CONSTEXPR_P (stmt)) stmt = integer_nonzerop (cond) ? then_ : else_; + /* ??? This optimization doesn't seem to belong here, but removing it + causes -Wreturn-type regressions (e.g. 107310). */ + else if (integer_nonzerop (cond) && !TREE_SIDE_EFFECTS (else_)) + stmt = then_; + else if (integer_zerop (cond) && !TREE_SIDE_EFFECTS (then_)) + stmt = else_; else stmt = build3 (COND_EXPR, void_type_node, cond, then_, else_); protected_set_expr_location_if_unset (stmt, locus); |