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.