[Bug c++/103375] New: [12 regression] -Werror=uninitialized false positive on unittest-cpp
slyfox at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Nov 23 08:17:07 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103375
Bug ID: 103375
Summary: [12 regression] -Werror=uninitialized false positive
on unittest-cpp
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: slyfox at gcc dot gnu.org
Target Milestone: ---
Initially build failure noticed on unittest-cpp-2.0.0. I suspect it's a week
old regression.
Here is the minimal extracted example:
$ cat TestTestRunner.cpp
struct TestReporter {};
struct TestRunner
{
explicit TestRunner(TestReporter& reporter);
// /*somewhere in .cpp:*/ : reporter_ (reporter) {}
TestReporter & reporter_; // only store reference
void RunAndReport();
};
struct FixtureBase
{
FixtureBase() : runner(reporter) {}
TestRunner runner;
TestReporter reporter;
};
$ g++-12.0.0 -O2 -Wall -Werror -c TestTestRunner.cpp
TestTestRunner.cpp: In constructor 'FixtureBase::FixtureBase()':
TestTestRunner.cpp:12:32: error: member 'FixtureBase::reporter' is used
uninitialized [-Werror=uninitialized]
12 | FixtureBase() : runner(reporter) {}
| ^~~~~~~~
cc1plus: all warnings being treated as errors
I think progaram's intent is to only store an object's reference at
construction time. And use it only in the rest of methods after construction is
done.
$ LANG=C g++-12.0.0 -v
Using built-in specs.
COLLECT_GCC=/nix/store/fxn6ca5x1yb1xj8rskkvw5zajrnj8y79-gcc-12.0.0/bin/g++
COLLECT_LTO_WRAPPER=/nix/store/fxn6ca5x1yb1xj8rskkvw5zajrnj8y79-gcc-12.0.0/libexec/gcc/x86_64-unknown-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with:
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20211121 (experimental) (GCC)
More information about the Gcc-bugs
mailing list