http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60741
Bug ID: 60741
Summary: [-Wmaybe-uninitialized] false negative and confusing
warning message
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: skvadrik at gmail dot com
Created attachment 32521
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32521&action=edit
wmaybe_uninitialized_strange_behavior.c
Given this code:
enum A { A1, A2 };
enum B { B1 };
static inline int fa (enum A a) {
int n;
switch (a) {
case A1: n = 1; break;
case A2: n = 2; break;
}
return n;
}
static inline int fb (enum B b) {
int n;
switch (b) {
case B1: n = 1; break;
}
return n;
}
int main (int argc, char **) {
return fa((A)argc) + fb((B)argc);
}
$ g++ -O1 -Wall wmaybe_uninitialized_strange_behavior.c
wmaybe_uninitialized_strange_behavior.c: In function ‘int main(int, char**)’:
wmaybe_uninitialized_strange_behavior.c:27:36: warning: ‘n’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
return fa((A)argc) + fb((B)argc);
^
1) gcc generates warning for 'fa' function, but not for 'fb' function.
2) The message points to the end of expression, that contains 'fa' call (not to
'fa' declaration, or at least to 'fa' call). The message mentions name of a
variable, that is used in 'fa' declaration. So we're lucky that the same name
doesn't appear in the calling function (main).
3) This all happens with -O1 or higher, with -O0 there's no warnings at all!