https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125203
Bug ID: 125203
Summary: [16 Regression] False positive -Wmaybe-uninitialized
for initializer list
Product: gcc
Version: 16.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ossman at cendio dot se
Target Milestone: ---
Upgrading from gcc 15.2 to 16.1 gives us this new warning in TigerVNC:
> ...
> [ 17%] Building CXX object common/core/CMakeFiles/core.dir/Exception.cxx.o
> /local/home/ossman/devel/tigervnc/common/core/Exception.cxx: In constructor
> 'core::getaddrinfo_error::getaddrinfo_error(const char*, int)':
> /local/home/ossman/devel/tigervnc/common/core/Exception.cxx:47:45: error:
> '<unknown>' may be used uninitialized [-Werror=maybe-uninitialized]
> 47 | strerror(err_).c_str(), err_)),
> | ~~~~~~~~^~~~~~
> /local/home/ossman/devel/tigervnc/common/core/Exception.cxx:60:13: note: by
> argument 1 of type 'const core::getaddrinfo_error*' to 'std::string
> core::getaddrinfo_error::strerror(int) const' declared here
> 60 | std::string getaddrinfo_error::strerror(int err_) const noexcept
> | ^~~~~~~~~~~~~~~~~
> ...
Very confusing "<unknown>" there. Fedora's gcc gives a bit better output for
unknown reasons:
> ...
> /builddir/build/BUILD/tigervnc-1.16.2-build/tigervnc-1.16.2/common/core/Exception.cxx:
> In member function ‘core::getaddrinfo_error::getaddrinfo_error(char const*,
> int)’:
> /builddir/build/BUILD/tigervnc-1.16.2-build/tigervnc-1.16.2/common/core/Exception.cxx:47:45:
> warning: ‘this_3(D)’ may be used uninitialized [-Wmaybe-uninitialized]
> 47 | strerror(err_).c_str(), err_)),
> | ~~~~~~~~^~~~~~
> ...
The issue seems to be with "this" in some way. The code in question calls a
(non-virtual) member function as part of an initializer list. So "this" is
under construction at this point. But that doesn't make it automatically unsafe
to use, making this warning needless noise.
We also use -Werror, making this even worse. It might force us to disable this
warning completely.
The complete code is easily available here (it's not much):
https://github.com/TigerVNC/tigervnc/blob/b434432bb7154f13ab2a3063925c19c6c7b55fd7/common/core/Exception.cxx
The member function in question doesn't actually need "this", so a workaround
in this case is to make it static.