[Bug c++/53210] New: warning for data member initialized with itself should be in -Wall
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu May 3 12:27:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53210
Bug #: 53210
Summary: warning for data member initialized with itself should
be in -Wall
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: redi@gcc.gnu.org
struct S {
S(int i) : j(j) { __builtin_printf("init'd to %d\n", i); }
int j;
};
The code has a typo, the mem-initializer should have been l(i)
G++ knows how to warn about the self-initialization, but only does so when
-Winit-self is used:
s.cc: In constructor 'S::S(int)':
s.cc:2:5: warning: 'S::j' is initialized with itself [-Wuninitialized]
Although the warning is enabled by -Winit-self it is reported as
-Wuninitialized (which kinda makes sense as it requires both to be active)
More importantly, I think this code should always warn.
-Winit-self is off to avoid warnings for (questionable) code which does
int i = i;
but there is no good reason to do that in a constructor's mem-initializer-list,
so no reason that -Wall shouldn't warn about it.
If you want 'i' to be uninitialized, simply leave it out of the
mem-initializer-list. Adding a mem-initializer that does self-init is just
perverse.
More information about the Gcc-bugs
mailing list