This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Can GCC warn unused and/or uninitialized C++ class attributes.


YingLCS@netscape.net writes:

> Hi,
> 
> Can GCC warn unused and/or uninitialized C++ class attributes?
> I look at the manual, it can warns about unused paramaters and
> uninitialized local variables. I would like ot know if it warns
> about unused and/or uninitialized C++ class attributes? If yes, how
> to enabled it? 
> 
> In C++, i can initalize attribues using member initializers or
> assignment in constructors.

Not true. Assignment is *not* initialization. If you do not explicitly
    initialize a member using a mem-initializer, it is
    default-initialized.

> Is GCC smart enough to understand both and find out which attributes
> are not initialized?

In principle ISO C++ initializes all data members. However, note that
    default-initialization of built-in types leaves them with
    undefined values (normal might not call this initialization, but
    the standard does... :-)

> I know there is an option "-Wreorder", but it only checks for order,
> it does not mention anything about uninitialized variables. 
[snip]

I think -Weffc++ almost does what you seem to want - trouble is, it
    generates lots of warnings for headers like <iostream> :-(.

gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Warning-Options.html#Warning%20Options

is a list of warning flags which affect both C and C++.

gcc.gnu.org/onlinedocs/gcc-3.3/gcc/C---Dialect-Options.html#C++%20Dialect%20Options

lists warning flags specific to C++ (note: you'll have to scroll to
    the bottom of the page; it's a list of all C++ dialect options,
    the first 0 or so of which are not warning flags.)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]