Follow practices suggested by "Effective C++"

The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:

* A class with virtual functions can no longer publicly inherit base
  classed without a vtable. The inherited object may either be moved
  to a member variable, or inherited privately. The latter would be
  used for classes that inherit 'List::Element' or 'Avl_node'. In order
  to enable the 'List' and 'Avl_tree' to access the meta data, the
  'List' must become a friend.

* Instead of adding a virtual destructor to abstract base classes,
  we inherit the new 'Interface' class, which contains a virtual
  destructor. This way, single-line abstract base classes can stay
  as compact as they are now. The 'Interface' utility resides in
  base/include/util/interface.h.

* With the new warnings enabled, all member variables must be explicitly
  initialized. Basic types may be initialized with '='. All other types
  are initialized with braces '{ ... }' or as class initializers. If
  basic types and non-basic types appear in a row, it is nice to only
  use the brace syntax (also for basic types) and align the braces.

* If a class contains pointers as members, it must now also provide a
  copy constructor and assignment operator. In the most cases, one
  would make them private, effectively disallowing the objects to be
  copied. Unfortunately, this warning cannot be fixed be inheriting
  our existing 'Noncopyable' class (the compiler fails to detect that
  the inheriting class cannot be copied and still gives the error).
  For now, we have to manually add declarations for both the copy
  constructor and assignment operator as private class members. Those
  declarations should be prepended with a comment like this:

        /*
         * Noncopyable
         */
        Thread(Thread const &);
        Thread &operator = (Thread const &);

  In the future, we should revisit these places and try to replace
  the pointers with references. In the presence of at least one
  reference member, the compiler would no longer implicitly generate
  a copy constructor. So we could remove the manual declaration.

Issue #465
This commit is contained in:
Norman Feske
2017-12-21 15:42:15 +01:00
committed by Christian Helmuth
parent 2a33d9aa76
commit eba9c15746
763 changed files with 4936 additions and 3288 deletions

View File

@ -38,6 +38,12 @@ class Init::Buffered_xml
return ptr;
}
/*
* Noncopyable
*/
Buffered_xml(Buffered_xml const &);
Buffered_xml &operator = (Buffered_xml const &);
public:
/**

View File

@ -385,7 +385,8 @@ Init::Child::Route Init::Child::resolve_session_request(Service::Name const &ser
if (_config_rom_service.constructed() &&
!_config_rom_service->abandoned())
return Route { _config_rom_service->service(), label };
return Route { _config_rom_service->service(), label,
Session::Diag{false} };
/*
* \deprecated the support for the <configfile> tag will
@ -431,7 +432,8 @@ Init::Child::Route Init::Child::resolve_session_request(Service::Name const &ser
/* check for "session_requests" ROM request */
if (service_name == Rom_session::service_name()
&& label.last_element() == Session_requester::rom_name())
return Route { _session_requester.service() };
return Route { _session_requester.service(),
Session::Label(), Session::Diag{false} };
try {
Xml_node route_node = _default_route_accessor.default_route();

View File

@ -46,11 +46,9 @@ class Init::Child : Child_policy, Routed_service::Wakeup
*/
struct Id { unsigned value; };
struct Default_route_accessor { virtual Xml_node default_route() = 0; };
struct Default_caps_accessor { virtual Cap_quota default_caps() = 0; };
struct Ram_limit_accessor { virtual Ram_quota ram_limit() = 0; };
struct Default_route_accessor : Interface { virtual Xml_node default_route() = 0; };
struct Default_caps_accessor : Interface { virtual Cap_quota default_caps() = 0; };
struct Ram_limit_accessor : Interface { virtual Ram_quota ram_limit() = 0; };
private:
@ -159,7 +157,7 @@ class Init::Child : Child_policy, Routed_service::Wakeup
Resources _resources_from_start_node(Xml_node start_node, Prio_levels prio_levels,
Affinity::Space const &affinity_space,
Cap_quota default_cap_quota, Cap_quota cap_limit)
Cap_quota default_cap_quota, Cap_quota)
{
size_t cpu_quota_pc = 0;
bool constrain_phys = false;
@ -282,7 +280,7 @@ class Init::Child : Child_policy, Routed_service::Wakeup
Service &service() { return _service; }
};
Constructible<Inline_config_rom_service> _config_rom_service;
Constructible<Inline_config_rom_service> _config_rom_service { };
Session_requester _session_requester;
@ -313,7 +311,7 @@ class Init::Child : Child_policy, Routed_service::Wakeup
{ }
};
Constructible<Requested_resources> _requested_resources;
Constructible<Requested_resources> _requested_resources { };
Genode::Child _child { _env.rm(), _env.ep().rpc_ep(), *this };

View File

@ -27,7 +27,7 @@ class Init::Child_registry : public Name_registry, Child_list
{
private:
List<Alias> _aliases;
List<Alias> _aliases { };
bool _unique(const char *name) const
{

View File

@ -30,9 +30,9 @@ struct Init::Main : State_reporter::Producer, Child::Default_route_accessor,
{
Env &_env;
Registry<Init::Parent_service> _parent_services;
Registry<Routed_service> _child_services;
Child_registry _children;
Registry<Init::Parent_service> _parent_services { };
Registry<Routed_service> _child_services { };
Child_registry _children { };
Heap _heap { _env.ram(), _env.rm() };
@ -42,7 +42,7 @@ struct Init::Main : State_reporter::Producer, Child::Default_route_accessor,
Reconstructible<Verbose> _verbose { _config_xml };
Constructible<Buffered_xml> _default_route;
Constructible<Buffered_xml> _default_route { };
Cap_quota _default_caps { 0 };

View File

@ -66,7 +66,7 @@ class Init::Report_detail : Genode::Noncopyable
};
struct Init::Report_update_trigger
struct Init::Report_update_trigger : Interface
{
virtual void trigger_report_update() = 0;
};

View File

@ -321,8 +321,7 @@ void Init::Server::_handle_upgrade_session_request(Xml_node request,
}
void Init::Server::_handle_close_session_request(Xml_node request,
Parent::Client::Id id)
void Init::Server::_handle_close_session_request(Xml_node, Parent::Client::Id id)
{
_client_id_space.apply<Session_state>(id, [&] (Session_state &session) {
close_session(session); });

View File

@ -44,12 +44,12 @@ class Init::Server : Session_state::Ready_callback,
/*
* ID space of requests originating from the parent
*/
Id_space<Parent::Server> _server_id_space;
Id_space<Parent::Server> _server_id_space { };
/*
* ID space of requests issued to the children of init
*/
Id_space<Parent::Client> _client_id_space;
Id_space<Parent::Client> _client_id_space { };
/**
* Exception type
@ -61,7 +61,7 @@ class Init::Server : Session_state::Ready_callback,
*/
struct Service;
Registry<Service> _services;
Registry<Service> _services { };
/**
* Services provided by our children
@ -70,8 +70,8 @@ class Init::Server : Session_state::Ready_callback,
Report_update_trigger &_report_update_trigger;
Constructible<Attached_rom_dataspace> _session_requests;
Constructible<Signal_handler<Server> > _session_request_handler;
Constructible<Attached_rom_dataspace> _session_requests { };
Constructible<Signal_handler<Server> > _session_request_handler { };
/**
* \throw Service_denied

View File

@ -26,7 +26,7 @@ namespace Init {
}
class Init::Abandonable
class Init::Abandonable : Interface
{
private:
@ -65,13 +65,13 @@ class Init::Routed_service : public Async_service, public Abandonable
typedef Child_policy::Name Child_name;
struct Ram_accessor
struct Ram_accessor : Interface
{
virtual Ram_session &ram() = 0;
virtual Ram_session_capability ram_cap() const = 0;
};
struct Pd_accessor
struct Pd_accessor : Interface
{
virtual Pd_session &pd() = 0;
virtual Pd_session_capability pd_cap() const = 0;

View File

@ -27,7 +27,7 @@ class Init::State_reporter : public Report_update_trigger
{
public:
struct Producer
struct Producer : Interface
{
virtual void produce_state_report(Xml_generator &xml,
Report_detail const &) const = 0;
@ -39,11 +39,11 @@ class Init::State_reporter : public Report_update_trigger
Producer &_producer;
Constructible<Reporter> _reporter;
Constructible<Reporter> _reporter { };
size_t _buffer_size = 0;
Reconstructible<Report_detail> _report_detail;
Reconstructible<Report_detail> _report_detail { };
unsigned _report_delay_ms = 0;
@ -52,10 +52,10 @@ class Init::State_reporter : public Report_update_trigger
/* version string from config, to be reflected in the report */
typedef String<64> Version;
Version _version;
Version _version { };
Constructible<Timer::Connection> _timer;
Constructible<Timer::Connection> _timer_periodic;
Constructible<Timer::Connection> _timer { };
Constructible<Timer::Connection> _timer_periodic { };
Signal_handler<State_reporter> _timer_handler {
_env.ep(), *this, &State_reporter::_handle_timer };