User account creation filtered due to spam.

Bug 40059 - "uninitialized" warning missed when uninitialized class member used as array index
Summary: "uninitialized" warning missed when uninitialized class member used as array ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2009-05-07 11:25 UTC by Daniel Pinol
Modified: 2017-03-02 10:23 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.5
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Pinol 2009-05-07 11:25:46 UTC
Compiling this code with "g++-4.4 -O -Wall -g kk.cpp -fdiagnostics-show-option"...
==============
struct S
{
int a;
};

int main()
{
  S s;
  int i;
  bool arr[1];
  arr[s.a] =true;  /*line 11: missed*/  
  arr[i] = true;
/*  if (s.a)
    return 1;
*/

  return 0;
}
==============


produces
kk.cpp:12: warning: ‘i’ is used uninitialized in this function [-Wuninitialized]

It realizes 1 bug, but not the one at line 11 (arr[s.a] =true)


However, if we uncomment the "if (s.a)" it does detect this usage of uninitialized variable

kk.cpp:8: warning: ‘s.S::a’ is used uninitialized in this function [-Wuninitialized]


thanks
Comment 1 Bart Van Assche 2010-02-24 11:46:47 UTC
gcc 4.3.4 doesn't complain about dereferencing uninitialized member variables either.
Comment 2 Manuel López-Ibáñez 2010-02-24 11:58:24 UTC
(In reply to comment #1)
> gcc 4.3.4 doesn't complain about dereferencing uninitialized member variables
> either.
> 

Please, open a new PR, attach a self-contained testcase, add PR 24639 to the block list of the new PR, and add me to the CC list. I will eventually look at it when I find the time.

Thanks.
Comment 3 Richard Biener 2017-03-02 10:23:57 UTC
Works at least since 4.8 and since GCC 5 also with -O0:

> ../../gcc5-g/gcc/cc1plus -quiet t.C -Wuninitialized
t.C: In function ‘int main()’:
t.C:11:10: warning: ‘s.S::a’ is used uninitialized in this function [-Wuninitialized]
    arr[s.a] =true;  /*line 11: missed*/  
          ^
t.C:12:19: warning: ‘i’ is used uninitialized in this function [-Wuninitialized]
      arr[i] = true;
                   ^