[Bug c++/96003] [11 Regression] Maybe a false positive for -Werror=nonnull
slyfox at inbox dot ru
gcc-bugzilla@gcc.gnu.org
Thu Jul 16 07:37:08 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96003
--- Comment #7 from Sergei Trofimovich <slyfox at inbox dot ru> ---
Similar example from xmms2 project, dynamic_cast<> version:
#include <typeinfo>
// main loop interface
struct I {
virtual void run();
};
struct M : public I {
virtual void run();
void setup_M();
};
struct Client
{
// In real code Client() always initializes mainloop_ with non-NULL 'M*'
pointer;
I* mainloop_;
Client();
void run_client();
void connect() {
if (mainloop_ && typeid(mainloop_) == typeid(M)) {
dynamic_cast<M*>(mainloop_)->setup_M( );
}
}
};
$ LANG=C x86_64-pc-linux-gnu-g++-11.0.0 -c bug.cpp -o a.o -Werror=nonnull
bug.cpp: In member function 'void Client::connect()':
bug.cpp:22:49: error: 'this' pointer null [-Werror=nonnull]
22 | dynamic_cast<M*>(mainloop_)->setup_M( );
| ^
bug.cpp:10:10: note: in a call to non-static member function 'void
M::setup_M()'
10 | void setup_M();
| ^~~~~~~
cc1plus: some warnings being treated as errors
Original code is from
https://github.com/xmms2/xmms2-devel/blob/dedc33d7408e140bce714c2c3eb5bcc793f1af6c/src/clients/lib/xmmsclient%2B%2B/client.cpp#L85
More information about the Gcc-bugs
mailing list