Fortran: Fix PR 47485.
[gcc.git] / gcc / testsuite / g++.dg / warn / Wnonnull9.C
blob88bf55adba24b6b42791371582ed4272adc909ab
1 /* PR c++/98646 - spurious -Wnonnull calling a member on the result
2    of static_cast
3    { dg-do compile }
4    { dg-options "-O2 -Wall" } */
6 struct A { virtual ~A (); };
7 struct B
9   virtual ~B ();
10   B* bptr ();
11   B& bref ();
14 struct C: A, B { virtual ~C (); void g () const; };
17 void c_cast_C_ptr (B *p)
19   ((C*)p->bptr ())->g ();
22 void c_cast_const_C_ptr (B *p)
24   ((const C*)p->bptr ())->g ();
27 void static_cast_C_ptr (B *p)
29   static_cast<C*>(p->bptr ())->g ();
32 void static_cast_const_C_ptr (B *p)
34   /* The static_cast can't fail so verify that no warning is issued
35      here, even though GCC emits a null check for its argument.  */
36   static_cast<const C*>(p->bptr ())->g ();    // { dg-bogus "\\\[-Wnonnull" }
39 void dynamic_cast_C_ptr (B *p)
41   /* Unlike static_cast, dynamic cast may return null even for a nonnull
42      operand but detecting assumptions to the contrary isn't -Wnonnull's
43      purpose.  Verify -Wnonnull isn't issued, either for the implicitly
44      emitted null check or for other reasons (the latter may be worth
45      warning for by some other warning).  See also pr99251.  */
46   dynamic_cast<C*>(p->bptr ())->g ();         // { dg-bogus "\\\[-Wnonnull" }
49 void dynamic_cast_const_C_ptr (B *p)
51   dynamic_cast<const C*>(p->bptr ())->g ();   // { dg-bogus "\\\[-Wnonnull" }
55 void c_cast_C_ref (B *p)
57   ((C&)p->bref ()).g ();
60 void c_cast_const_C_ref (B *p)
62   ((const C&)p->bref ()).g ();
65 void static_cast_C_ref (B *p)
67   static_cast<C&>(p->bref ()).g ();
70 void static_cast_const_C_ref (B *p)
72   static_cast<const C&>(p->bref ()).g ();
75 void dynamic_cast_C_ref (B *p)
77   /* The dynamic_cast fails by throwing an exception so verify that
78      no warning is issued.  */
79   dynamic_cast<C&>(p->bref ()).g ();
82 void dynamic_cast_const_C_ref (B *p)
84   dynamic_cast<const C&>(p->bref ()).g ();
88 struct D: B, A { virtual ~D (); void g () const; };
90 void c_cast_D_ptr (B *p)
92   ((D*)p->bptr ())->g ();
95 void c_cast_const_D_ptr (B *p)
97   ((const D*)p->bptr ())->g ();
100 void static_cast_D_ptr (B *p)
102   static_cast<D*>(p->bptr ())->g ();
105 void static_cast_const_D_ptr (B *p)
107   /* The static_cast can't fail so verify that no warning is issued
108      here, even though GCC emits a null check for its argument.  */
109   static_cast<const D*>(p->bptr ())->g ();    // { dg-bogus "\\\[-Wnonnull" }
112 void dynamic_cast_D_ptr (B *p)
114   /* Unlike static_cast, dynamic cast may return null even for a nonnull
115      operand but detecting assumptions to the contrary isn't -Wnonnull's
116      purpose.  Verify -Wnonnull isn't issued, either for the implicitly
117      emitted null check or for other reasons (the latter may be worth
118      warning for by some other warning).  See also pr99251.  */
119   dynamic_cast<D*>(p->bptr ())->g ();         // { dg-bogus "\\\[-Wnonnull" }
122 void dynamic_cast_const_D_ptr (B *p)
124   dynamic_cast<const D*>(p->bptr ())->g ();   // { dg-bogus "\\\[-Wnonnull" }