[PATCH c++] Reduce -Weffc++ Rule 12 false positives

Dirk Mueller dmueller@suse.de
Tue Feb 7 23:57:00 GMT 2006


On Wednesday, 8. February 2006 00:46, Gabriel Dos Reis wrote:

> The only odd about it is the warning about "B::right".

You can suppress that one by reformatting your code: 

struct B
{
  B() : right() { bogus = 42; }
  int bogus;
  A right;
}

This produces 100% identical output and satisfies (largley) the C++ rule. Of 
course you can do the same for bogus as well: 

struct B
{
  B() : right(), bogus() { bogus = 42; }
  int bogus;
  A right;
}

But if that is more maintainable is questionable. It also depends on if imply 
an ordering of construction in your initializer list. Most code I've seen 
puts the stuff that doesn't depend on construction order in the initializer 
list, and the other one (that possibly even depends on allocations and oder 
complicated decisions) in the constructor body. 

> We seem to have a different understanding of what that Item 12 is about.

I agree :)

> That is why I would encourage you to reconsider the patch.

I guess we can not agree other than by collecting statistics about usefulness 
of this warning in one or the other case (hard to do), or by making the 
behaviour configurable. Or by ignoring this patch. 

> Yes, the current implementation is not perfect and makes lot of noise,
> but your proposed patch retains the worst noise and shut up the useful
> ones.

Depends on if you care about performance overhead due to unnecessary calls to 
default constructors (my point) or if you care about possibly partially 
constructed objects (your point, but a headache especially with mutable 
members). IMHO for the latter, you more need something like Purify or 
valgrind. However, unnecessary default constructor calls are better spotted 
by the compiler. 


Dirk



More information about the Gcc-patches mailing list