This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: V3 patch causes EH failures in ILP32 mode
On Wed, 23 Jun 2004 13:19:16 -0500, "B. Kosnik" <bkoz@nabi.net> said:
> Just out of curiosity, can't you also change this (AFAICT) textbook
> C++
It's really a side issue, but I wouldn't call it textbook C++ code at
all. The relevant _Effective C++_ rule (item 11) is "Declare a copy
constructor and an assignment operator for classes with dynamically
allocated memory"; the way I've seen that phrased elsewhere is "if you
have any of a destructor, copy constructor, or assignment operator,
you should have all of them".
That last rule is, of course, much too broad (e.g. because of smart
pointers), but my point is that the class in question doesn't work
with either rule. The class _doesn't_ dynamically manage memory, so
the _Effective C++_ rule doesn't apply. And the fact that it doesn't
dynamically manage memory is reflected in the fact that it doesn't
have a destructor (or a smart pointer which would manage the memory
for you, of course).
So I would hope that any decent C++ textbook would argue against
writing your own copy constructor and assignment operator in this
situation. It's prone to error, and it makes the code harder to read:
any reader of the code has to figure out what information the class
author was trying to convey by adding those member functions, and the
lack of a destructor makes their presence even more confusing.
Like I said, this is a side issue - if you really want your code to
pass -Weffc++ (and want to do that by changing the code as opposed to
fixing -Weffc++), a little bit of ugliness may be worth it, given that
you said elsewhere that -Weffc++ has caught real bugs. But ugliness
it is...
David Carlton
david.carlton@sun.com