gcc/testsuite/g++.dg/warn/Wnonnull12.C
raw| 1 | /* PR c++/99251 - inconsistent -Wnonnull warning behaviour with dynamic_cast |
| 2 | { dg-do compile } |
| 3 | { dg-options "-Wall" } */ |
| 4 | |
| 5 | struct A |
| 6 | { |
| 7 | virtual ~A (); |
| 8 | }; |
| 9 | |
| 10 | struct B: A |
| 11 | { |
| 12 | int f (int); |
| 13 | }; |
| 14 | |
| 15 | int f1 (A *p) |
| 16 | { |
| 17 | if (!p) |
| 18 | return 0; |
| 19 | |
| 20 | return (dynamic_cast<B *>(p))->f (1); |
| 21 | } |
| 22 | |
| 23 | int f2 (A *p) |
| 24 | { |
| 25 | if (!p) |
| 26 | return 0; |
| 27 | |
| 28 | return dynamic_cast<B *>(p)->f (2); // { dg-bogus "\\\[-Wnonnull" } |
| 29 | } |