Closed dlech closed 12 months ago
I think I remember seeing this warning and I'm pretty sure it's a false positive. If you check the code you see it does this:
if (this->outer())
{
return this->outer()->GetIids(count, array);
}
So it does check the pointer to be non-null before calling the member function. I am not sure if this is a GCC bug though, maybe the concern is that multiple calls to this->outer()
might return different values and it wants you to assign it to a local before checking?
Though you can find a list of bogus -Wnonnull
warnings in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=wnonnull so this warning is known to be a bit buggy.
This was also flagged by internal static analysis tooling. It is sound but may worth fixing just to avoid the noise.
Related to #1341.
The easiest fix would be
if (const auto outer = this->outer())
{
return outer->GetIids(count, array);
}
If that results in a clean build, feel free to offer a PR fix. There are a few such instances in base_implements.h
.
The easiest fix would be
I tried this, but still triggers the the same error:
C:/Users/david/Documents/GitHub/pywinrt/projection/winrt-sdk/src/winrt_sdk/cppwinrt/winrt/base.h: In instantiation of 'int32_t winrt::impl::root_implements<D, I>::GetIids(uint32_t*, winrt::guid**) [with D = py::python_iterable<winrt::Windows::Foundation::Collections::IKeyValuePair<winrt::hstring, winrt::hstring> >::iterator; I = {winrt::Windows::Foundation::Collections::IIterator<winrt::Windows::Foundation::Collections::IKeyValuePair<winrt::hstring, winrt::hstring> >}; int32_t = int; uint32_t = unsigned int]':
C:/Users/david/Documents/GitHub/pywinrt/projection/winrt-sdk/src/winrt_sdk/cppwinrt/winrt/base.h:8163:49: required from 'winrt::impl::hresult_type winrt::implements<D, I>::GetIids(winrt::impl::count_type*, winrt::impl::guid_type**) [with D = py::python_iterable<winrt::Windows::Foundation::Collections::IKeyValuePair<winrt::hstring, winrt::hstring> >::iterator; I = {winrt::Windows::Foundation::Collections::IIterator<winrt::Windows::Foundation::Collections::IKeyValuePair<winrt::hstring, winrt::hstring> >}; winrt::impl::hresult_type = int; winrt::impl::count_type = unsigned int; winrt::impl::guid_type = winrt::guid]'
C:/Users/david/Documents/GitHub/pywinrt/projection/winrt-sdk/src/winrt_sdk/cppwinrt/winrt/base.h:7197:34: required from 'int32_t winrt::impl::produce_base<D, I, Enable>::GetIids(uint32_t*, winrt::guid**) [with D = py::python_iterable<winrt::Windows::Foundation::Collections::IKeyValuePair<winrt::hstring, winrt::hstring> >::iterator; I = winrt::Windows::Foundation::Collections::IIterator<winrt::Windows::Foundation::Collections::IKeyValuePair<winrt::hstring, winrt::hstring> >; Enable = void; int32_t = int; uint32_t = unsigned int]'
C:/Users/david/Documents/GitHub/pywinrt/projection/winrt-sdk/src/winrt_sdk/cppwinrt/winrt/base.h:7195:27: required from here
C:/Users/david/Documents/GitHub/pywinrt/projection/winrt-sdk/src/winrt_sdk/cppwinrt/winrt/base.h:7573:24: error: 'this' pointer is null [-Werror=nonnull]
7573 | return outer->GetIids(count, array);
| ^~~~~
C:/Users/david/Documents/GitHub/pywinrt/projection/winrt-sdk/src/winrt_sdk/cppwinrt/winrt/base.h:1766:39: note: in a call to non-static member function 'virtual int32_t winrt::impl::abi<winrt::Windows::Foundation::IInspectable>::type::GetIids(uint32_t*, winrt::guid**)'
1766 | virtual int32_t __stdcall GetIids(uint32_t* count, guid** ids) noexcept = 0;
| ^~~~~~~
I found that outer()
was defined with constexpr
in one template which seemed to be triggering the warning. I've made a pull request to remove it to avoid the warning.
Version
No response
Summary
In the WinRT Python bindings project, I tried building on MINGW32 using GCC 13 with
-Werror -Wall -Wextra
compiler options. This triggers-Werror=nonnull
inwinrt/base.h
(see full error below).Is this a GCC bug or something that can/should be fixed in cppwrint?
Reproducible example
Expected behavior
GCC should compile without errors like MSVC and Clang.
Actual behavior
Additional comments
No response