C++ PATCH to fix missing warning (PR c++/70194)
Jakub Jelinek
jakub@redhat.com
Tue Mar 15 10:56:00 GMT 2016
On Tue, Mar 15, 2016 at 11:41:20AM +0100, Marek Polacek wrote:
> This is to fix missing "address of %qD will never be NULL" warning that went
> away since the delayed folding merge. The problem was that cp_build_binary_op
> was getting unfolded ops so in the constexpr case it saw "(int *) p" instead of
> "&i" (in this particular testcase). Fixed by calling fold_non_dependent_expr
> as is done elsewhere.
> (It doesn't seem like the "if (CONVERT_EXPR_P (op?)" blocks need to use cop?
> too.)
>
> I did not try to address the other issues Martin has raised in the PR yet.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2016-03-15 Marek Polacek <polacek@redhat.com>
>
> PR c++/70194
> * typeck.c (cp_build_binary_op): Call fold_non_dependent_expr before
> warning about an address not being null.
>
> * g++.dg/warn/constexpr-70194.C: New test.
>
> diff --git gcc/cp/typeck.c gcc/cp/typeck.c
> index 20f0afc..a789c7a 100644
> --- gcc/cp/typeck.c
> +++ gcc/cp/typeck.c
> @@ -4520,14 +4520,16 @@ cp_build_binary_op (location_t location,
> else
> result_type = type0;
>
> - if (TREE_CODE (op0) == ADDR_EXPR
> - && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0)))
> + tree cop0 = fold_non_dependent_expr (op0);
> +
> + if (TREE_CODE (cop0) == ADDR_EXPR
> + && decl_with_nonnull_addr_p (TREE_OPERAND (cop0, 0)))
>From compile time perspective, I wonder if it wouldn't be better to do
the cheap tests early, like:
if (warn_address
&& (complain & tf_warning)
&& c_inhibit_evaluation_warnings == 0
&& !TREE_NO_WARNING (op0))
{
tree cop0 = fold_non_dependent_expr (op0);
if (TREE_CODE (cop0) == ADDR_EXPR
&& decl_with_nonnull_addr_p (TREE_OPERAND (cop0, 0))
&& !TREE_NO_WARNING (cop0))
warning (OPT_waddress, "the address of %qD will never be NULL",
TREE_OPERAND (cop0, 0));
}
thus perform fold_non_dependent_expr only if it is needed.
Furthermore, I wonder if it isn't preferrable to %qD the non-folded
expression (if it is ADDR_EXPR, that is), so perhaps:
TREE_OPERAND (TREE_CODE (op0) == ADDR_EXPR ? op0 : cop0, 0)
?
Jakub
More information about the Gcc-patches
mailing list