This is the mail archive of the gcc-help@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: Redundant warning with -Weffc++


Andrew Haley wrote:
David Sveningsson wrote:
Hi, when I compile the code below with -Weffc++ I get warnings about the
initialization list.

class Foo {
public:
         Foo(): x(0), y(0){
         }

private:
         union {
                 struct {
                         float x;
                         float y;
                 };
                 float v[2];
         };
};

initialization.cpp: In constructor ‘Foo::Foo()’:
initialization.cpp:3: warning: ‘Foo::<anonymous>’ should be initialized
in the member initialization list
initialization.cpp:3: warning: ‘Foo::<anonymous union>::<anonymous>’
should be initialized in the member initialization list

I don't think this warning is correct as all memory has been initalized
correctly.

I don't think so. We know that v is at the same address as x, but v[1] may not be at the same address as y. However, I see your point: there doesn't seem to be any way to make -Weffc++ work with this.

Andrew.

Yes but if a field in the union is fully initialized it shouldn't warn about the others. That's kind of the point with a union.


Also, it warns about the anonymous struct too. Both its fields is initialized but it still warns that the struct is not.

class Foo {
public:
        Foo(): x(0), y(0){
        }

private:
        struct {
                float x;
                float y;
        };
};

initialization.cpp: In constructor ‘Foo::Foo()’:
initialization.cpp:3: warning: ‘Foo::<anonymous>’ should be initialized in the member initialization list



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