This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/72826] New: Poor diagnostic for uninitialized structure field
- From: "zackw at panix dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 06 Aug 2016 14:50:32 +0000
- Subject: [Bug c++/72826] New: Poor diagnostic for uninitialized structure field
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72826
Bug ID: 72826
Summary: Poor diagnostic for uninitialized structure field
Product: gcc
Version: 6.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: zackw at panix dot com
Target Milestone: ---
This cut-down test program...
extern "C" int puts(const char *);
struct countdownTimer {
countdownTimer() : paused{ true } {}
void start() noexcept {
if (started) return;
started = true;
puts("timer started");
}
private:
char dummy[32];
bool paused;
bool started;
};
int main() {
countdownTimer timer;
timer.start();
}
... produces these diagnostics when compiled with `-O2 -Wall [-std=c++11]`:
test2.cc: In function ‘int main()’:
test2.cc:8:13: warning: ‘*((void*)& timer +33)’ is used uninitialized in this
function [-Wuninitialized]
if (started) return;
^~~~~~~
test2.cc:20:20: note: ‘*((void*)& timer +33)’ was declared here
countdownTimer timer;
^~~~~
The behavior is the same in g++ 5 and 6, except that you need -std=c++11 with
g++ 5.
`*((void*)& timer +33)` is internal representation-ese that should not be
dumped into a diagnostic. It should somehow manage to produce `timer.started`
instead.