https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69922
Bug ID: 69922 Summary: Bogus -Wnonnull-compare for: ... ? static_cast<T*>(this) : nullptr Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sbergman at redhat dot com Target Milestone: --- 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