[Bug c++/69922] Bogus -Wnonnull-compare for: ... ? static_cast<T*>(this) : nullptr

2016-02-23 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69922

--- Comment #2 from Markus Trippelsdorf  ---
(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(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(this) : nullptr; }
> >^~~
> > cc1plus: all warnings being treated as errors

BTW, this style of posting (quoting the code) makes copy it
unnecessary hard. Please avoid it in the future.

[Bug c++/69922] Bogus -Wnonnull-compare for: ... ? static_cast<T*>(this) : nullptr

2016-02-23 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69922

Markus Trippelsdorf  changed:

   What|Removed |Added

 CC||trippels at gcc dot gnu.org

--- Comment #1 from Markus Trippelsdorf  ---
Jakub, can you please check all the different C++ casts for similar issues?

dynamic_cast (should be fine now)
reinterpret_cast
static_cast
const_cast