This is the mail archive of the gcc@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: How to get unused variable warning for non-PODs


On Wed, Feb 23, 2005 at 10:14:22AM +0100, "Richter, Jörg" wrote:

> I want to know if its possible to get warnings for unused variables that
> have a user defined constructor and/or destructor.

> I know that they are side-effect free and want to mark them for the
> compiler. But neither attribute const nor pure helped me here.

> Btw: std::string would be IMO a good candidate for such an attribute.

We certainly wouldn't want such a warning in the general case, as it would
break the common use of constructors and destructors to allocate and free
resources.  But you're right that it would be nice to warn about unused
class objects where we know that the object is "pure waste".

> Any ideas how to achieve this with GCC 3.4.x?

I don't think that there is a way to do it with 3.4.x, sorry.  Such a
feature would have to be designed.  Also, strictly speaking std::string's
constructor has side effects (allocation and freeing of memory,
manipulation of reference counts), so it would be necessary to tell
the compiler explicitly that such side effects don't matter.  For classes
where the constructor and destructor are inline, and only initialize
fields, then in principle the compiler could figure this out on its own
if someone contributes the right patch.  There is the "small" matter
that we might only be able to tell that the constructor is side-effect
free with the optimizer on (so that inlining is performed).


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