public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103375] New: [12 regression] -Werror=uninitialized false positive on unittest-cpp
@ 2021-11-23 8:17 slyfox at gcc dot gnu.org
2021-11-23 8:26 ` [Bug c++/103375] [12 regression] -Werror=uninitialized false positive on unittest-cpp since r12-5391-g0790c8aacdfb4f pinskia at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: slyfox at gcc dot gnu.org @ 2021-11-23 8:17 UTC (permalink / raw)
To: gcc-bugs
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)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103375] [12 regression] -Werror=uninitialized false positive on unittest-cpp since r12-5391-g0790c8aacdfb4f
2021-11-23 8:17 [Bug c++/103375] New: [12 regression] -Werror=uninitialized false positive on unittest-cpp slyfox at gcc dot gnu.org
@ 2021-11-23 8:26 ` pinskia at gcc dot gnu.org
2021-11-23 8:29 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-23 8:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103375
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
CC| |mpolacek at gcc dot gnu.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103375] [12 regression] -Werror=uninitialized false positive on unittest-cpp since r12-5391-g0790c8aacdfb4f
2021-11-23 8:17 [Bug c++/103375] New: [12 regression] -Werror=uninitialized false positive on unittest-cpp slyfox at gcc dot gnu.org
2021-11-23 8:26 ` [Bug c++/103375] [12 regression] -Werror=uninitialized false positive on unittest-cpp since r12-5391-g0790c8aacdfb4f pinskia at gcc dot gnu.org
@ 2021-11-23 8:29 ` pinskia at gcc dot gnu.org
2021-11-23 8:32 ` slyfox at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-23 8:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103375
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-11-23
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
If you swap the order of runner and reporter you don't get the uninitialized
warning.
I do have to wonder if the warning should be improved in messaging here because
it is not obvious why this might be bad.
In this case maybe used before is initialized due to order of the variables or
something to that effect.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103375] [12 regression] -Werror=uninitialized false positive on unittest-cpp since r12-5391-g0790c8aacdfb4f
2021-11-23 8:17 [Bug c++/103375] New: [12 regression] -Werror=uninitialized false positive on unittest-cpp slyfox at gcc dot gnu.org
2021-11-23 8:26 ` [Bug c++/103375] [12 regression] -Werror=uninitialized false positive on unittest-cpp since r12-5391-g0790c8aacdfb4f pinskia at gcc dot gnu.org
2021-11-23 8:29 ` pinskia at gcc dot gnu.org
@ 2021-11-23 8:32 ` slyfox at gcc dot gnu.org
2021-11-23 8:54 ` slyfox at gcc dot gnu.org
2021-11-23 23:14 ` mpolacek at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: slyfox at gcc dot gnu.org @ 2021-11-23 8:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103375
--- Comment #2 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
Created attachment 51855
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51855&action=edit
a.cpp.cpp
Also attaching unmodified preprocessed original file as I might have removed
too much. Original example uses inheritance with virtual functions.
gcc complains as:
$ g++-12.0.0 -std=c++14 -Werror=uninitialized -c a.cpp.cpp
a.cpp.cpp: In constructor '{anonymous}::FixtureBase::FixtureBase()':
a.cpp.cpp:23467:19: error: member '{anonymous}::FixtureBase::reporter' is used
uninitialized [-Werror=uninitialized]
23467 | : runner(reporter)
| ^~~~~~~~
cc1plus: some warnings being treated as errors
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103375] [12 regression] -Werror=uninitialized false positive on unittest-cpp since r12-5391-g0790c8aacdfb4f
2021-11-23 8:17 [Bug c++/103375] New: [12 regression] -Werror=uninitialized false positive on unittest-cpp slyfox at gcc dot gnu.org
` (2 preceding siblings ...)
2021-11-23 8:32 ` slyfox at gcc dot gnu.org
@ 2021-11-23 8:54 ` slyfox at gcc dot gnu.org
2021-11-23 23:14 ` mpolacek at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: slyfox at gcc dot gnu.org @ 2021-11-23 8:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103375
--- Comment #3 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
Proposed upstream workaround as
https://github.com/unittest-cpp/unittest-cpp/pull/185.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103375] [12 regression] -Werror=uninitialized false positive on unittest-cpp since r12-5391-g0790c8aacdfb4f
2021-11-23 8:17 [Bug c++/103375] New: [12 regression] -Werror=uninitialized false positive on unittest-cpp slyfox at gcc dot gnu.org
` (3 preceding siblings ...)
2021-11-23 8:54 ` slyfox at gcc dot gnu.org
@ 2021-11-23 23:14 ` mpolacek at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-11-23 23:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103375
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|NEW |RESOLVED
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The reduced test no longer warns.
The unreduced warns, but that seems to be a good thing, just switch the order
of these:
23480 TestRunner runner;
23481 RecordingReporter reporter;
Not a bug, IMHO.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-11-23 23:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-23 8:17 [Bug c++/103375] New: [12 regression] -Werror=uninitialized false positive on unittest-cpp slyfox at gcc dot gnu.org
2021-11-23 8:26 ` [Bug c++/103375] [12 regression] -Werror=uninitialized false positive on unittest-cpp since r12-5391-g0790c8aacdfb4f pinskia at gcc dot gnu.org
2021-11-23 8:29 ` pinskia at gcc dot gnu.org
2021-11-23 8:32 ` slyfox at gcc dot gnu.org
2021-11-23 8:54 ` slyfox at gcc dot gnu.org
2021-11-23 23:14 ` mpolacek at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).