This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Uninitilised variable detection in C++
Hi naveen,
On Mon, May 18, 2009 at 07:14:28PM +0530, naveen yadav wrote:
> Hi
> I am using GNU compiler and i enable all warnings still i do not get any
> warning.
> Is there any way to get warning for uninitilised variables in c++ .
>
Probably you are looking for "-Weffc++". That reports for your file
warning: âFoo::m_nValueâ should be initialized in the member initialization list
> class Foo
> {
> private:
> Â int m_nValue;
> public:
> Â Foo();
> Â int GetValue() { return m_bValue; }
> };
> Foo::Foo()
> {
> Â // Oops, we forget to initialize m_nValue
> }
> int main()
> {
> Â Foo cFoo;
> Â if (cFoo.GetValue() > 0)
> Â Â Â // do something
> Â else
> Â Â Â // do something else
> }
Axel