diff options
author | Martin Sebor <msebor@redhat.com> | 2021-03-02 11:12:50 -0700 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2021-03-02 11:12:50 -0700 |
commit | 66ecb059c9d77cfcfb06cbdc3cac6a63b9e67f3d (patch) | |
tree | ecb475f0a8a856dcd03e0b200c71257f9c1911e9 /gcc/cp/class.c | |
parent | 5a233ae4d8c978a3c863c8199d6c3050389a84d1 (diff) | |
download | gcc-66ecb059c9d77cfcfb06cbdc3cac6a63b9e67f3d.tar.gz |
PR c++/99251 - inconsistent -Wnonnull warning behaviour with dynamic_cast
gcc/cp/ChangeLog:
PR c++/99251
* class.c (build_base_path): Call build_if_nonnull.
* cp-tree.h (build_if_nonnull): Declare.
* rtti.c (ifnonnull): Rename...
(build_if_nonnull): ...to this. Set no-warning bit on COND_EXPR.
(build_dynamic_cast_1): Adjust to name change.
gcc/testsuite/ChangeLog:
PR c++/99251
* g++.dg/warn/Wnonnull9.C: Expect no warnings.
* g++.dg/warn/Wnonnull12.C: New test.
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r-- | gcc/cp/class.c | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c index ea007e88e6e..856e81e3d1a 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -402,16 +402,9 @@ build_base_path (enum tree_code code, if (TREE_SIDE_EFFECTS (expr) && (null_test || virtual_access)) expr = save_expr (expr); - /* Now that we've saved expr, build the real null test. */ + /* Store EXPR and build the real null test just before returning. */ if (null_test) - { - tree zero = cp_convert (TREE_TYPE (expr), nullptr_node, complain); - null_test = build2_loc (input_location, NE_EXPR, boolean_type_node, - expr, zero); - /* This is a compiler generated comparison, don't emit - e.g. -Wnonnull-compare warning for it. */ - TREE_NO_WARNING (null_test) = 1; - } + null_test = expr; /* If this is a simple base reference, express it as a COMPONENT_REF. */ if (code == PLUS_EXPR && !virtual_access @@ -516,14 +509,8 @@ build_base_path (enum tree_code code, out: if (null_test) - { - expr = fold_build3_loc (input_location, COND_EXPR, target_type, null_test, - expr, build_zero_cst (target_type)); - /* Avoid warning for the whole conditional expression (in addition - to NULL_TEST itself -- see above) in case the result is used in - a nonnull context that the front end -Wnonnull checks. */ - TREE_NO_WARNING (expr) = 1; - } + /* Wrap EXPR in a null test. */ + expr = build_if_nonnull (null_test, expr, complain); return expr; } |