https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98646
Bug ID: 98646 Summary: A static_cast confuses -Wnonnull, causing false positives Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ville.voutilainen at gmail dot com Target Milestone: --- Created attachment 49957 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49957&action=edit Preprocessed source Compile with /usr/local/bin/c++ -DQT_ASCII_CAST_WARNINGS -DQT_BUILDING_QT -DQT_BUILD_XCB_PLUGIN -DQT_BUILD_XCB_QPA_LIB_LIB -DQT_CORE_LIB -DQT_DEPRECATED_WARNINGS -DQT_DEPRECATED_WARNINGS_SINCE=0x060000 -DQT_DISABLE_DEPRECATED_BEFORE=0x050000 -DQT_GUI_LIB -DQT_MOC_COMPAT -DQT_NO_CAST_TO_ASCII -DQT_NO_EXCEPTIONS -DQT_NO_FOREACH -DQT_OPENGL_LIB -DQT_USE_QSTRINGBUILDER -DXcbQpa_EXPORTS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -fno-exceptions -fPIC -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -Wno-error=strict-overflow -Wno-error=implicit-fallthrough -Wno-error=deprecated-copy -Wno-error=redundant-move -Wno-error=init-list-lifetime -Wno-error=format-overflow -Wsuggest-override -std=c++17 -c winid-nonnull.cpp The result is /home/vivoutil/kuutti/kuuttikutonen/qt5/qtbase/src/plugins/platforms/xcb/qxcbwindow.cpp: In member function ‘void QXcbWindow::show()’: /home/vivoutil/kuutti/kuuttikutonen/qt5/qtbase/src/plugins/platforms/xcb/qxcbwindow.cpp:685:91: error: ‘this’ pointer null [-Werror=nonnull] 685 | transientXcbParent = static_cast<const QXcbWindow *>(tp->handle())->winId(); | ^ In file included from /home/vivoutil/kuutti/kuuttikutonen/qt5/qtbase/src/plugins/platforms/xcb/qxcbwindow.cpp:40: /home/vivoutil/kuutti/kuuttikutonen/qt5/qtbase/src/plugins/platforms/xcb/qxcbwindow.h:87:9: note: in a call to non-static member function ‘virtual WId QXcbWindow::winId() const’ 87 | WId winId() const override; | ^~~~~ Removing the static_cast removes the warning.