Avoid unused variable warnings (PR #23077)

226 views
Skip to first unread message

PB

unread,
Dec 25, 2022, 8:50:20 AM12/25/22
to wx-...@googlegroups.com, Subscribed

For some reason there has been a couple of variables declared, written to, but for some reason never read from. I have removed them, assuming this is a correct thing to do.

Using CMake 64-bit Debug build with MSVC 2022 v17.4.3, GCC 12.2, and clang 15.0; the only remaining warning in the library is

D:\Dev\Desktop\!Lib\wxWidgets-PB\src\richtext\richtextbuffer.cpp:4902:17: warning: variable 'i' set but not used [-Wunused-but-set-variable]
            int i = 0;

The variable is used only in a conditionally compiled block

#if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING && wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS
if (i < (int) line->GetObjectSizes().GetCount())
{
objectSize.x = line->GetObjectSizes()[(size_t) i];
}
else
#endif

so I don't know what to do, aside from using wxUnusedVar() or declaring the variable also in a similar conditionally compiled block. Neither sounds appealing but I guess one has to be picked.

There is also a warning about missing enum switch value in the webview2 SDK but I suppose suppressing warnings in 3rd party code would be too much work.

There is still a bunch of warning in the samples and benchmarks but I think these are much lower priority when in comes to warning-less build. I would still like to address them in the future, if possible.


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/23077

Commit Summary

  • 1f47d32 Remove unused variable in Generic progress dialog code
  • d8fc164 Remove unused variable from ribbon toolbar code
  • 7629da8 Remove unused variables from rich text control code
  • b4a29df Remove unused variable from the dialogs sample

File Changes

(5 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23077@github.com>

VZ

unread,
Dec 25, 2022, 11:35:25 AM12/25/22
to wx-...@googlegroups.com, Subscribed

Thanks for fixing this, I'll merge it soon (unless you tell me you're going to push more changes to this branch).

Concerning the remaining warnings:

  • Using #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING && wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS around the other uses of i looks best here as it more clearly shows that it's only used for this. Perhaps we could hide i++ into the already existing block to avoid adding another #if check.
  • For the warnings in the headers, we typically use pragma push/pop before/after including them.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23077/c1364707051@github.com>

PB

unread,
Dec 25, 2022, 11:55:32 AM12/25/22
to wx-...@googlegroups.com, Push

@PBfordev pushed 1 commit.

  • abe6d5a Avoid unused variable warning in rich text control code


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23077/push/12100820535@github.com>

PB

unread,
Dec 25, 2022, 12:09:13 PM12/25/22
to wx-...@googlegroups.com, Subscribed

I have fixed the rich text issue discussed above which means I am done with this PR.

I have only now noticed that one of the two webview2-related issues is actually in our code:

D:\Dev\Desktop\!Lib\wxWidgets-PB\src\msw\webview_edge.cpp:429:21: warning: enumeration values 'COREWEBVIEW2_WEB_ERROR_STATUS_VALID_AUTHENTICATION_CREDENTIALS_REQUIRED' and 'COREWEBVIEW2_WEB_ERROR_STATUS_VALID_PROXY_AUTHENTICATION_REQUIRED' not handled in switch [-Wswitch]
            switch (status)
                    ^~~~~~

but as I am not sure how to best handle it I will leave it be, hoping @TcT2k or @MaartenBent will fix it sometime in the future.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23077/c1364711069@github.com>

PB

unread,
Dec 25, 2022, 12:15:48 PM12/25/22
to wx-...@googlegroups.com, Push

@PBfordev pushed 1 commit.

  • 42079fd Add missing #if guard around a variable


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23077/push/12100892929@github.com>

PB

unread,
Dec 25, 2022, 2:28:33 PM12/25/22
to wx-...@googlegroups.com, Subscribed

CI failure is unrelated.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23077/c1364728071@github.com>

Maarten

unread,
Dec 27, 2022, 9:21:50 AM12/27/22
to wx-...@googlegroups.com, Subscribed

I don't see the webview warnings, but I suspect they depend on the version of the webview2 sdk. They should probably be mapped to wxWEBVIEW_NAV_ERR_AUTH?

I do see an other warning with clang (also in the CI log), from a recent change:

In file included from D:/dev/wxWidgets/include/wx/msw/statbox.h:14:
D:/dev/wxWidgets/include/wx/compositewin.h:147:26: warning: 'GetCompositeWindowParts' overrides a member function but is not marked 'override'
      [-Winconsistent-missing-override]
    virtual wxWindowList GetCompositeWindowParts() const = 0;
                         ^
D:/dev/wxWidgets/include/wx/compositewin.h:177:34: note: in instantiation of template class 'wxCompositeWindowSettersOnly<wxStaticBox>' requested here
class wxCompositeWindow : public wxCompositeWindowSettersOnly<W>
                                 ^
D:/dev/wxWidgets/include/wx/msw/radiobox.h:23:44: note: in instantiation of template class 'wxCompositeWindow<wxStaticBox>' requested here
class WXDLLIMPEXP_CORE wxRadioBox : public wxCompositeWindow<wxStaticBox>,
                                           ^
D:/dev/wxWidgets/include/wx/msw/statbox.h:80:26: note: overridden virtual function is here
    virtual wxWindowList GetCompositeWindowParts() const override;
                         ^

and with GCC:

D:\dev\wxWidgets\src\propgrid\propgrid.cpp: In member function 'void wxPropertyGrid::HandleKeyEvent(wxKeyEvent&, bool)':
D:\dev\wxWidgets\src\propgrid\propgrid.cpp:5727:54: warning: 'secondAction' may be used uninitialized [-Wmaybe-uninitialized]
 5727 |             if ( action == wxPG_ACTION_PREV_PROPERTY || secondAction == wxPG_ACTION_PREV_PROPERTY )
      |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\dev\wxWidgets\src\propgrid\propgrid.cpp:5645:9: note: 'secondAction' was declared here
 5645 |     int secondAction;
      |         ^~~~~~~~~~~~
In member function 'void wxHashTableBase::Create(wxKeyType, size_t)',
    inlined from 'void wxHashTable::DoCopy(const wxHashTable&)' at D:\dev\wxWidgets\src\common\hash.cpp:339:11,
    inlined from 'wxHashTable::wxHashTable(const wxHashTable&)' at D:\dev\wxWidgets\src\common\hash.cpp:326:11:
D:\dev\wxWidgets\src\common\hash.cpp:62:20: warning: array subscript 0 is outside array bounds of 'void [0]' [-Warray-bounds]
   62 |         m_table[i] = nullptr;
      |         ~~~~~~~~~~~^~~~~~~~~
D:\dev\wxWidgets\src\common\hash.cpp:59:49: note: object of size 0 allocated by 'operator new []'
   59 |     m_table = new wxHashTableBase_Node*[ m_size ];
      |                                                 ^
In member function 'void wxHashTableBase::Create(wxKeyType, size_t)',
    inlined from 'void wxHashTable::DoCopy(const wxHashTable&)' at D:\dev\wxWidgets\src\common\hash.cpp:339:11,
    inlined from 'const wxHashTable& wxHashTable::operator=(const wxHashTable&)' at D:\dev\wxWidgets\src\common\hash.cpp:332:11:
D:\dev\wxWidgets\src\common\hash.cpp:62:20: warning: array subscript 0 is outside array bounds of 'void [0]' [-Warray-bounds]
   62 |         m_table[i] = nullptr;
      |         ~~~~~~~~~~~^~~~~~~~~
D:\dev\wxWidgets\src\common\hash.cpp:59:49: note: object of size 0 allocated by 'operator new []'
   59 |     m_table = new wxHashTableBase_Node*[ m_size ];
      |                                                 ^

And two weird (invalid?) ones caused by using wxT("")/wxS(""). Could be fixed by replacing them with wxString(), but I don't really know what's going on here.

 Building CXX object libs/core/CMakeFiles/wxcore.dir/__/__/__/__/src/msw/headerctrl.cpp.obj
In file included from D:/dev/wxWidgets/include/wx/chartype.h:52,
                 from D:/dev/wxWidgets/include/wx/debug.h:17,
                 from D:/dev/wxWidgets/include/wx/defs.h:865,
                 from D:/dev/wxWidgets/include/wx/wxprec.h:12,
                 from D:/dev/build/wxWidgets/mingw64/rlsmsw/libs/core/CMakeFiles/wxcore.dir/cmake_pch.hxx:5,
                 from <command-line>:
In function 'wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t)',
    inlined from 'static std::char_traits<wchar_t>::char_type* std::char_traits<wchar_t>::copy(char_type*, const char_type*, std::size_t)' at D:/msys64/mingw64/inc
lude/c++/12.2.0/bits/char_traits.h:558:16,
    inlined from 'static void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = wchar_t; _Traits = std
::char_traits<wchar_t>; _Alloc = std::allocator<wchar_t>]' at D:/msys64/mingw64/include/c++/12.2.0/bits/basic_string.h:423:21,
    inlined from 'static void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = wchar_t; _Traits = std
::char_traits<wchar_t>; _Alloc = std::allocator<wchar_t>]' at D:/msys64/mingw64/include/c++/12.2.0/bits/basic_string.h:418:7,
    inlined from 'static void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy_chars(_CharT*, const _CharT*, const _CharT*) [with _CharT = wchar_t; _Tr
aits = std::char_traits<wchar_t>; _Alloc = std::allocator<wchar_t>]' at D:/msys64/mingw64/include/c++/12.2.0/bits/basic_string.h:477:16,
    inlined from 'void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_InIterator, _InIterator, std::forward_iterator_tag) [with _FwdIterator =
const wchar_t*; _CharT = wchar_t; _Traits = std::char_traits<wchar_t>; _Alloc = std::allocator<wchar_t>]' at D:/msys64/mingw64/include/c++/12.2.0/bits/basic_string
.tcc:243:21,
    inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = wchar_t; _Traits = std::char_trait
s<wchar_t>; _Alloc = std::allocator<wchar_t>]' at D:/msys64/mingw64/include/c++/12.2.0/bits/basic_string.h:642:14,
    inlined from 'wxString::wxString(const wchar_t*)' at D:/dev/wxWidgets/include/wx/string.h:1154:7,
    inlined from 'bool wxMSWHeaderCtrl::Create(wxWindow*, wxWindowID, const wxPoint&, const wxSize&, long int, const wxString&)' at D:\dev\wxWidgets\src\msw\header
ctrl.cpp:246:27:
D:/msys64/mingw64/include/wchar.h:1502:31: warning: 'void* memcpy(void*, const void*, size_t)' forming offset [2, 3] is out of the bounds [0, 2] [-Warray-bounds]
 1502 |     return (wchar_t *) memcpy (_S1,_S2,_N*sizeof(wchar_t));
Building CXX object libs/xml/CMakeFiles/wxxml.dir/__/__/__/__/src/xml/xml.cpp.obj
In file included from D:/dev/wxWidgets/include/wx/chartype.h:52,
                 from D:/dev/wxWidgets/include/wx/debug.h:17,
                 from D:/dev/wxWidgets/include/wx/defs.h:865,
                 from D:/dev/wxWidgets/include/wx/wxprec.h:12,
                 from D:/dev/build/wxWidgets/mingw64/rlsmsw/libs/xml/CMakeFiles/wxxml.dir/cmake_pch.hxx:5,
                 from <command-line>:
In function 'wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t)',
    inlined from 'static std::char_traits<wchar_t>::char_type* std::char_traits<wchar_t>::copy(char_type*, const char_type*, std::size_t)' at D:/msys64/mingw64/inc
lude/c++/12.2.0/bits/char_traits.h:558:16,
    inlined from 'static void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = wchar_t; _Traits = std
::char_traits<wchar_t>; _Alloc = std::allocator<wchar_t>]' at D:/msys64/mingw64/include/c++/12.2.0/bits/basic_string.h:423:21,
    inlined from 'static void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = wchar_t; _Traits = std
::char_traits<wchar_t>; _Alloc = std::allocator<wchar_t>]' at D:/msys64/mingw64/include/c++/12.2.0/bits/basic_string.h:418:7,
    inlined from 'static void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy_chars(_CharT*, const _CharT*, const _CharT*) [with _CharT = wchar_t; _Tr
aits = std::char_traits<wchar_t>; _Alloc = std::allocator<wchar_t>]' at D:/msys64/mingw64/include/c++/12.2.0/bits/basic_string.h:477:16,
    inlined from 'void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_InIterator, _InIterator, std::forward_iterator_tag) [with _FwdIterator =
const wchar_t*; _CharT = wchar_t; _Traits = std::char_traits<wchar_t>; _Alloc = std::allocator<wchar_t>]' at D:/msys64/mingw64/include/c++/12.2.0/bits/basic_string
.tcc:243:21,
    inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = wchar_t; _Traits = std::char_trait
s<wchar_t>; _Alloc = std::allocator<wchar_t>]' at D:/msys64/mingw64/include/c++/12.2.0/bits/basic_string.h:642:14,
    inlined from 'wxString::wxString(const wchar_t*)' at D:/dev/wxWidgets/include/wx/string.h:1154:7,
    inlined from 'void StartCdataHnd(void*)' at D:\dev\wxWidgets\src\xml\xml.cpp:731:60:
D:/msys64/mingw64/include/wchar.h:1502:31: warning: 'void* memcpy(void*, const void*, size_t)' forming offset [2, 3] is out of the bounds [0, 2] [-Warray-bounds]
 1502 |     return (wchar_t *) memcpy (_S1,_S2,_N*sizeof(wchar_t));


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23077/c1365938052@github.com>

VZ

unread,
Dec 27, 2022, 10:47:40 AM12/27/22
to wx-...@googlegroups.com, Subscribed

We need to explicitly disable -Winconsistent-missing-override in wxCompositeWindow code, just as we already do it for gcc. In fact, we probably need a new macro (wxOVERRIDE_WARNING_SUPPRESS?) to do it for both compilers to avoid making things too ugly. I wonder why this hasn't resulted in an error in the CI builds, they're supposed to use -Werror...

The -Warray-bounds ones I don't understand, does it happen with -O2 only? But it's true that we can always replace wxT("") with wxString{} which is also marginally more efficient, so we can do it regardless.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23077/c1366001698@github.com>

PB

unread,
Dec 27, 2022, 11:43:01 AM12/27/22
to wx-...@googlegroups.com, Subscribed

I don't see the webview warnings, but I suspect they depend on the version of the webview2 sdk. They should probably be mapped to wxWEBVIEW_NAV_ERR_AUTH?

BTW, wxWidgets currently requires webview2 SDK v1.0.864.35, but according to the docs, those two enum values were introduced only in v1.0.1108.44, so they can be used only in a version-guarded compile-time check.

I do see an other warning with clang (also in the CI log), from a recent change:

This is probably in the code not in my PR branch (or not shown in the debug build?). Since I am heavily GIT-impaired, I will not attempt to fix them in this PR. Last time I tried to rebase my PR branch on the master, it went horribly wrong.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23077/c1366036359@github.com>

VZ

unread,
Dec 28, 2022, 7:47:14 PM12/28/22
to wx-...@googlegroups.com, Subscribed

Merged #23077 into master.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/23077/issue_event/8123757211@github.com>

Reply all
Reply to author
Forward
0 new messages