[Bug c++/16166] -Weffc++ finer granularity

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Nov 7 16:14:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16166

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-11-07 16:10:10 UTC ---
Reviewing these warnings w.r.t the much improved third edition...

(In reply to comment #1)
> # Item 11: Define a copy constructor and an assignment operator for classes with
> dynamically allocated memory.

Replaced by Item 14: "Think carefully about copying behavior in
resource-managing classes" - the advice is less specific, but more useful.  I'm
not sure how to turn it into a warning though!

> # Item 12: Prefer initialization to assignment in constructors.

Replaced by Item 4: "Make sure that objects are initialized before they're
used", and G++ misinterprets the original item anyway and warns about *any*
member without a mem-initializer, which is very annoying: there's no point
initializing a std::string, it has a perfectly safe default constructor.  My
-Wmeminit patch for PR 2972 should replace the current warning for this item,
as it only warns about members left uninitialized by the constructor.

> # Item 14: Make destructors virtual in base classes.

Adjusted to Item 7: "Declare destructors virtual in polymorphic base classes",
the warning is still relevant (but -Wdelete-non-virtual-dtor is more useful
IMHO)

> # Item 15: Have operator= return a reference to *this.

Renumbered to Item 10. Still relevant.

> # Item 23: Don't try to return a reference when you must return an object.

Renumbered to Item 21. Still relevant.

> # Item 6: Distinguish between prefix and postfix forms of increment and
> decrement operators.
> # Item 7: Never overload &&, ||, or ,.

These are from More Effective C++ which only has one edition.



More information about the Gcc-bugs mailing list