This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/69922] Bogus -Wnonnull-compare for: ... ? static_cast<T*>(this) : nullptr
- From: "trippels at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 23 Feb 2016 16:02:04 +0000
- Subject: [Bug c++/69922] Bogus -Wnonnull-compare for: ... ? static_cast<T*>(this) : nullptr
- Auto-submitted: auto-generated
- References: <bug-69922-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69922
--- Comment #2 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
(In reply to Stephan Bergmann from comment #0)
> With trunk@233631:
>
> > $ cat test.cc
> > struct S2 { virtual ~S2(); };
> > struct S1 {
> > virtual ~S1();
> > S2 * f(bool);
> > };
> > struct S3: S1, S2 {};
> > S2 * S1::f(bool b) { return b ? static_cast<S3 *>(this) : nullptr; }
>
> > $ g++ -Werror -Wnonnull-compare -c test.cc
> > test.cc: In member function âS2* S1::f(bool)â:
> > test.cc:7:59: error: nonnull argument âthisâ compared to NULL [-Werror=nonnull-compare]
> > S2 * S1::f(bool b) { return b ? static_cast<S3 *>(this) : nullptr; }
> > ^~~~~~~
> > cc1plus: all warnings being treated as errors
BTW, this style of posting (quoting the code) makes copy&pasting it
unnecessary hard. Please avoid it in the future.