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: Warning on C++ catch by value on non primitive types


On Fri, Oct 14, 2005 at 01:55:49AM +0200, Gabriel Dos Reis wrote:
> What I find the most annoying with -Weffc++ is not the rules
> themselves; but the fact that is that it is a set of guidelines
> designed for a *particular style* of programming in C++ 

That is, traditional OO programming.

> many people see it as _The Right Way_ of doing things in C++, forgetting
> this is a multi-paradigm language

In particular, generic programming, as represented in STL and Boost.

> I do not find it surprising
> that major software components like libstdc++ or Boost do not
> slavishly follow -Weffc++ -- I would have been surprised if they did.

It seems that the key issue with -Weffc++ is that it is overly paranoid
about the possibility that someone will destroy a derived object through
a base pointer or reference, resulting in the wrong destructor being
called, even in cases where neither the base class nor the derived class
have any virtual functions.  In the case of no virtual functions, the
base/derived relationship is just a means of factoring out common code;
a typical STL example would be the deriving of a function object from
something like std::binary_function<T1,T2,Tresult>, or in the construction
of reverse iterators.

Furthermore, there are many cases where calling the wrong destructor is
a no-op in any real GCC implementation (e.g. both the base and derived
classes have one data member, a POD, and there is no explicit destructor,
or the only side effect is in the base destructor).  Most of the
STL-related noises -Weffc++ makes were, as I recall, related to such
cases.  Maybe it could be made to shut up only about particular cases
known to be safe.







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