void *ctx, tree param,
unsigned HOST_WIDE_INT param_num)
{
+ if (TREE_NO_WARNING (param))
+ return;
+
if (CONVERT_EXPR_P (param)
&& (TYPE_PRECISION (TREE_TYPE (param))
== TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param, 0)))))
out:
if (null_test)
- expr = fold_build3_loc (input_location, COND_EXPR, target_type, null_test, expr,
- build_zero_cst (target_type));
+ {
+ 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;
+ }
return expr;
}
--- /dev/null
+/* PR c++/96003 - spurious -Wnonnull calling a member on the result
+ of static_cast
+ { dg-do compile }
+ { dg-options "-Wall" } */
+
+struct D;
+struct B
+{
+ B* next;
+ D* Next ();
+};
+
+struct D: B
+{
+ virtual ~D ();
+};
+
+struct Iterator
+{
+ D* p;
+ void advance ()
+ {
+ p = static_cast<B*>(p)->Next (); // { dg-bogus "\\\[-Wnonnull" }
+ }
+};
+
+// Test case from comment #11.
+
+struct S1 { virtual ~S1 (); };
+struct S2 { virtual ~S2 (); };
+struct S3: S1, S2 { void f (); };
+
+void f (S2 *p)
+{
+ static_cast<S3 *>(p)->f (); // { dg-bogus "\\\[-Wnonnull" }
+}