https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107411
Bug ID: 107411 Summary: trivial-auto-var-init=zero invalid uninitialized variable warning Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: davidwelch158 at hotmail dot com Target Milestone: --- Created attachment 53774 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53774&action=edit preprocessed reproduction case Compiling this file #include <cstdio> class HostLayer { public: int getError(); }; void queryString(HostLayer& m_host) { const auto& error = m_host.getError(); printf("%d\n", error); } with the command line on x86-64 Ubuntu 22.04 g++ -Werror=uninitialized -ftrivial-auto-var-init=zero -c OverrideLayer.cpp and the latest gcc trunk (GCC12 is also affected) produces the warning. OverrideLayer.cpp: In function ‘void queryString(HostLayer&)’: OverrideLayer.cpp:12:45: error: ‘D.2933’ is used uninitialized [-Werror=uninitialized] 12 | const auto& error = m_host.getError(); | ^ OverrideLayer.cpp:12:45: note: ‘D.2933’ was declared here 12 | const auto& error = m_host.getError(); | which seems to be invalid and also doesn't identify the problem variable. Compiling with /home/dw/devel/gcc/install/bin/g++ -Werror=uninitialized -c OverrideLayer.cpp finishes without error. g++ -v Using built-in specs. COLLECT_GCC=/home/dw/devel/gcc/install/bin/g++ COLLECT_LTO_WRAPPER=/home/dw/devel/gcc/install/libexec/gcc/x86_64-linux-gnu/13.0.0/lto-wrapper Target: x86_64-linux-gnu Configured with: ../configure --enable-languages=c,c++ --prefix=/home/dw/devel/gcc/install --enable-shared --enable-linker-build-id --without-included-gettext --enable-threads=posix --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.0.0 20221025 (experimental) (GCC) lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy