samedi 23 avril 2016

-Weffc++ warning on simple structure with shared_ptr

I try to compile very simple tree node with std::shared_ptr. In my compiler options I use -Weffc++ and -Werror but it throws 2 errors which I don't understand thus I can't imagine a solution.

The minimal example (t.cpp):

#include <memory>

struct node {
    std::shared_ptr<node> left;
    std::shared_ptr<node> right;
    std::shared_ptr<int> value;
};

int main() {
    node n;
    return 0;
}

The output from compiler is:

$ LANG=en_US g++ -std=c++14 -Weffc++ t.cpp
t.cpp: In constructor 'constexpr node::node()':
t.cpp:3:8: warning: 'node::left' should be initialized in the member initialization list [-Weffc++]
 struct node {
        ^
t.cpp:3:8: warning: 'node::right' should be initialized in the member initialization list [-Weffc++]
t.cpp:3:8: warning: 'node::value' should be initialized in the member initialization list [-Weffc++]
t.cpp: In function 'int main()':
t.cpp:10:10: note: synthesized method 'constexpr node::node()' first required here 
     node n;
          ^

The only similiar thing I could find is this question but it does not answer on my question unfortunately.

Aucun commentaire:

Enregistrer un commentaire