[Bug c++/57917] New: -Wuninitialized

2013-07-17 Thread nishant.031 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57917

Bug ID: 57917
   Summary: -Wuninitialized
   Product: gcc
   Version: 4.2.4
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: nishant.031 at gmail dot com

Hi,
Please see code snippet below.
g++ -v gave me following output:
g++ -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: /home/gcc-4.2.4/configure --prefix=/usr/local/soft/gcc/4.2.4
--disable-nls --enable-languages=c,c++
Thread model: posix
gcc version 4.2.4

In the code below, class variable isABC is not initialized. We came across a
crash in one particular RHEL machine which got fixed once I initialized this
variable in the class constructor. In another machine, the software started
giving absurd results until I initialized this variable in constructor.

I thought of finding an option in gcc which can report uninitialized variables
in class. I finally came across -Wuninitialized. I compiled this code using:
g++ test.cpp -Wuninitialized -O3

I was not reported any warning in this case. Is this the correct usage? If not,
is there any switch that can report such warning?


=

class A
{
private:
bool isABC;
public:
void setABC(bool);
};
void A::setABC(bool flag)
{
isABC = flag;
}

int main()
{
A a;
return -1;
}

===

But, the following case reports the following warning:

test.cpp: In function 'int main()':
test.cpp:31: warning: 'a.A::a' is used uninitialized in this function
test.cpp:38: note: 'a.A::a' was declared here

--
class A {
bool ggg;
  int a;
public:
  void mA() {
printf("haha");
++a;
int g = 2/a;
printf("%i\n",g);
  }
};

int main() {
  A a;
  a.mA();
  return -1;
}


Thanks.
Please help.


[Bug c++/57917] -Wuninitialized

2013-07-17 Thread nishant.031 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57917

Nishant Sharma  changed:

   What|Removed |Added

   Severity|normal  |critical


[Bug c++/57917] -Wuninitialized

2013-07-17 Thread nishant.031 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57917

--- Comment #2 from Nishant Sharma  ---
(In reply to Jonathan Wakely from comment #1)
> GCC 4.2 is ancient and no longer supported.
> 
> This is not "critical", it's your code that has a bug, not the compiler.
> 
> You don't use A::isABC in the program, so it's a poor testcase.
> 
> There are lots of existing PRs about this, e.g. PR 2972 and PR 42000 and PR
> 19808
> 
> *** This bug has been marked as a duplicate of bug 19808 ***

Even if from main, if I execute: a.setABC(false);
Then also it does NOT report a warning.
This should have worked isn't it?

My main intent is to ask how to catch such warnings?


[Bug c++/57917] -Wuninitialized

2013-07-17 Thread nishant.031 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57917

Nishant Sharma  changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|DUPLICATE   |---

--- Comment #3 from Nishant Sharma  ---
Even if from main, if I execute: a.setABC(false);
Then also it does NOT report a warning.
This should have worked isn't it?

What should be done so that compiler treats this as a warning OR do you think
this is not a valid case for being reported & if not, then why would compiler
not report anything?