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


Dirk Mueller <dmueller@suse.de> writes:

| 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. 

but, that it not what your code implements.  It implements something
different if I read your patch correctly.

+struct B
+{
+  B() {}
+
+  int bogus;         // { dg-bogus "should be initialized in the member" }
+  nontriv right;     // { dg-warning "should be initialized in the member" }
+};

We should be warning to the effect that B::bogus is not initialized.  

-- Gaby


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