Bug 55837 - [C++11] -Weffc++: warning: 'xxx:yyy' should be initialized in the member initialization list
Summary: [C++11] -Weffc++: warning: 'xxx:yyy' should be initialized in the member init...
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Weffc++
  Show dependency treegraph
 
Reported: 2012-12-31 23:40 UTC by Lars Hamrén
Modified: 2019-11-22 05:36 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Self-contained source file (202 bytes, text/x-c++src)
2012-12-31 23:40 UTC, Lars Hamrén
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Hamrén 2012-12-31 23:40:47 UTC
Created attachment 29067 [details]
Self-contained source file

This code

    static struct Error {
        int child_pid = 0;
        struct {
            bool s_sensor = false;
        } opt;
    } ss;

gives a warning message

    'Error::opt' should be initialized in the member initialization list [-Weffc++]

But Error::opt is already initialized, since its only member is initialized.

/Lars Hamrén
Comment 1 Andrew Pinski 2013-01-01 00:10:17 UTC
-Weffc++ warnings are not designed with C++11 in mind.
Comment 2 Lars Hamrén 2013-01-01 00:21:56 UTC
I do realize that this is a clash between an old-ish rule and the new C++11 syntax.

However, the spirit of the underlying rule (which I assume is that "all members should be initialized") still applies, and the rule, and its implementation, could be updated for C++11.
Comment 3 Jonathan Wakely 2013-01-01 01:34:54 UTC
Or don't use -Weffc++, it's close to useless
Comment 4 Jonathan Wakely 2013-01-01 02:48:27 UTC
This warning also complains if you don't have a mem-initializer for a type such as std::string, which has a perfectly safe default constructor i.e. the warning is just broken by design.

What's really needed is to replace the current "there is no explicit initializer for some member" with a warning about members that are left uninitialized, so we don't warn about members with a non-static data member initializer or with a default constructor.  I was working on exactly that, but never got it working correctly in all cases.  I plan to return to that patch soonish.