1
私は非常に単純なツリーノードをstd::shared_ptr
でコンパイルしようとしています。私のコンパイラのオプションで私は-Weffc++
と-Werror
を使用しますが、私は解決できないと私は理解できない2つのエラーをスローします。-WeffC++ shared_ptrを使った簡単な構造の警告
最小限の例(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;
}
コンパイラからの出力は次のとおりです。
$ 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;
^
私は見つけることができる唯一の事は似this questionですが、それは上の答えはありません残念ながら私の質問。
は、デフォルトコンストラクタを追加してみてください?コンパイラが生成したものが誤ってconstexprであると推測されているように見える –
@RichardHodgesありがとう、あなたのアドバイスはconstexprに関するsecodnd警告のクリーンアップに役立ちました。しかし、** russw_uk **の答えはすべての警告をきれいにする。 –
ああクールです。だから、それは単にeffcフラグまで下がっていました。 –