This is the mail archive of the gcc-patches@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: [PATCH c++] Reduce -Weffc++ Rule 12 false positives


On Tuesday, 7. February 2006 22:54, Gabriel Dos Reis wrote:

> I don't really believe that that is the point of the guideline.  The rule
> is t have people initialize things.  If you have a default constructor that
> leaves some members uninitialized, that is asking for trouble.

Ok, I make an example. 

=== Cut ===
class A {
public:
    A() : m(0) {}
    A(int i) : m(i) {}

   int m;
};

class B
   A a;
public:
   B()  { a = A(5); }
};
=== Cut ===

Here, B::B() produces two calls. one to A::A() and one to A::A(int) (and a 
copy constructor/assigment, which is elided as its a pure value based class). 
This is what it IMHO should warn about, because this code: 

B::B()
  : A(5)
{}

does the same, just is much more efficient. 


Dirk






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