The message is relatively quite clear in my opinion, assuming it points to the copy constructor specifically. It could be improved by referring to the problematic base as well though.
Node
inherits enable_shared_from_this<Node>
. The copy constructor which you define manually does not mention this base class in the initializer list. Therefore the base class will be default-initialized. Having a base class or member be default initialized in a copy constructor is very likely to not have the intended effect and much more likely to be an oversight. This is why clang-tidy produces the diagnostic.
In this particular situation here there is no problem with enable_shared_from_this<Node>
being default-initialized, since its copy constructor is defined to perform the same action as its default constructor. But that is a rare exception.
You can satisfy clang-tidy and avoid relying on this special case, by correctly initializing the base as well:
Node(const Node &that) : enable_shared_from_this(that), parent(that.parent) { /*...*/}
However, you have more serious problems here. First, std::enable_shared_from_this
must be inherited publicly. You are currently inheriting it privately.
Second, you cannot use shared_from_this
inside a constructor. When the constructor runs, the object which is being constructed is not yet under control of a std::shared_ptr
. As a result calling shared_from_this
will simply throw std::bad_weak_ptr
(since C++17; undefined behavior before that).