Hm, good eye.
-> In this case, ISTM we could remove the default false
argument in the constructor declaration
-> As to your last point, it suggests the default member m_inbound_onion
initializer not set a value, since we are doing it dynamically in the ctor. It’s true that I see a build error in this case, but not without the change in net.h:1099
0/src/net.cpp
1- nMyStartingHeight(nMyStartingHeightIn),
2- m_inbound_onion(inbound_onion && conn_type_in == ConnectionType::INBOUND)
3+ nMyStartingHeight(nMyStartingHeightIn)
4
5/src/net.h
6 //! Whether this peer is an inbound onion, e.g. connected via our Tor onion service.
7- const bool m_inbound_onion{false};
8+ const bool m_inbound_onion;
0net.cpp:2947:1: error: uninitialized const member in ‘const bool’ [-fpermissive]
1 2947 | CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion)
2 | ^~~~~
3In file included from net.cpp:10:
4./net.h:1099:16: note: ‘const bool CNode::m_inbound_onion’ should be initialized
5 1099 | const bool m_inbound_onion;
6 | ^~~~~~~~~~~~~~~
I don’t mind pulling in a commit from your branch if you’d like to adjust this.
More generally, from what I can gather, the ideas behind in-class default member initializers added in C++11 were (a) to allow a non-static data member to be initialized where it is declared, e.g. in its class. A constructor can then use the initializer when run-time initialization is needed, which can then (b) tidy up the code up by avoiding doing it in the member initializer list of the constructor. This provides extra benefits in classes with multiple constructors.
I guess one can see the default member initializer as the general default, particularly useful for constant initializers, that can be overridden by any specific ones in member initializer lists in the constructors.
Some resources (send me any good ones you might suggest; my understanding on this is evolving):