Skip to content

Commit 877e986

Browse files
committed
Fix bugprone-crtp-constructor-accessibility clang-tidy errors
CRTP base classes used in a two-level hierarchy (base -> intermediate -> final) need protected constructors so the intermediate template can call them. Add NOLINTNEXTLINE suppression since the tidy check doesn't account for multi-level CRTP. Intermediate "finals" templates use private constructors with friend Derived as the check recommends.
1 parent 2aae214 commit 877e986

7 files changed

Lines changed: 37 additions & 24 deletions

File tree

include/boost/corosio/native/detail/reactor/reactor_acceptor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class reactor_acceptor
6060
friend Derived;
6161

6262
protected:
63+
// NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility)
6364
explicit reactor_acceptor(Service& svc) noexcept : svc_(svc) {}
6465

6566
protected:

include/boost/corosio/native/detail/reactor/reactor_acceptor_service.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class reactor_acceptor_service : public ServiceBase
4848
using state_type = reactor_service_state<Scheduler, Impl>;
4949

5050
protected:
51+
// NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility)
5152
explicit reactor_acceptor_service(capy::execution_context& ctx)
5253
: ctx_(ctx)
5354
, state_(

include/boost/corosio/native/detail/reactor/reactor_datagram_socket.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class reactor_datagram_socket
8484
friend Derived;
8585

8686
protected:
87+
// NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility)
8788
explicit reactor_datagram_socket(Service& svc) noexcept : base_type(svc) {}
8889

8990
protected:

include/boost/corosio/native/detail/reactor/reactor_service_finals.hpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,16 @@ class reactor_tcp_service_impl
169169
using base_service = reactor_socket_service<
170170
Derived, tcp_service,
171171
typename Traits::scheduler_type, SocketFinal>;
172+
friend Derived;
172173
friend base_service;
173174

175+
explicit reactor_tcp_service_impl(capy::execution_context& ctx)
176+
: base_service(ctx) {}
177+
174178
public:
175179
static constexpr bool needs_write_notification =
176180
Traits::needs_write_notification;
177181

178-
explicit reactor_tcp_service_impl(capy::execution_context& ctx)
179-
: base_service(ctx) {}
180-
181182
std::error_code open_socket(
182183
tcp_socket::implementation& impl,
183184
int family, int type, int protocol) override
@@ -219,15 +220,16 @@ class reactor_local_stream_service_impl
219220
using base_service = reactor_socket_service<
220221
Derived, local_stream_service,
221222
typename Traits::scheduler_type, SocketFinal>;
223+
friend Derived;
222224
friend base_service;
223225

226+
explicit reactor_local_stream_service_impl(capy::execution_context& ctx)
227+
: base_service(ctx) {}
228+
224229
public:
225230
static constexpr bool needs_write_notification =
226231
Traits::needs_write_notification;
227232

228-
explicit reactor_local_stream_service_impl(capy::execution_context& ctx)
229-
: base_service(ctx) {}
230-
231233
std::error_code open_socket(
232234
local_stream_socket::implementation& impl,
233235
int family, int type, int protocol) override
@@ -260,15 +262,16 @@ class reactor_udp_service_impl
260262
using base_service = reactor_socket_service<
261263
Derived, udp_service,
262264
typename Traits::scheduler_type, SocketFinal>;
265+
friend Derived;
263266
friend base_service;
264267

268+
explicit reactor_udp_service_impl(capy::execution_context& ctx)
269+
: base_service(ctx) {}
270+
265271
public:
266272
static constexpr bool needs_write_notification =
267273
Traits::needs_write_notification;
268274

269-
explicit reactor_udp_service_impl(capy::execution_context& ctx)
270-
: base_service(ctx) {}
271-
272275
std::error_code open_datagram_socket(
273276
udp_socket::implementation& impl,
274277
int family, int type, int protocol) override
@@ -300,15 +303,16 @@ class reactor_local_dgram_service_impl
300303
using base_service = reactor_socket_service<
301304
Derived, local_datagram_service,
302305
typename Traits::scheduler_type, SocketFinal>;
306+
friend Derived;
303307
friend base_service;
304308

309+
explicit reactor_local_dgram_service_impl(capy::execution_context& ctx)
310+
: base_service(ctx) {}
311+
305312
public:
306313
static constexpr bool needs_write_notification =
307314
Traits::needs_write_notification;
308315

309-
explicit reactor_local_dgram_service_impl(capy::execution_context& ctx)
310-
: base_service(ctx) {}
311-
312316
std::error_code open_socket(
313317
local_datagram_socket::implementation& impl,
314318
int family, int type, int protocol) override
@@ -353,9 +357,9 @@ class reactor_acceptor_service_impl
353357
typename Traits::scheduler_type,
354358
AccFinal,
355359
StreamServiceFinal>;
360+
friend Derived;
356361
friend base_service;
357362

358-
public:
359363
explicit reactor_acceptor_service_impl(capy::execution_context& ctx)
360364
: base_service(ctx)
361365
{
@@ -364,6 +368,7 @@ class reactor_acceptor_service_impl
364368
this->ctx_.template find_service<StreamServiceFinal>();
365369
}
366370

371+
public:
367372
std::error_code open_acceptor_socket(
368373
typename AccFinal::impl_base_type& impl,
369374
int family, int type, int protocol) override

include/boost/corosio/native/detail/reactor/reactor_socket_finals.hpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,20 @@ class reactor_stream_socket_impl
6565
ImplBase,
6666
Endpoint>
6767
{
68+
friend Derived;
6869
friend Service;
6970

71+
explicit reactor_stream_socket_impl(Service& svc) noexcept
72+
: reactor_stream_socket_impl::reactor_stream_socket(svc)
73+
{
74+
}
75+
7076
public:
7177
using impl_base_type = ImplBase;
7278

7379
// Per-socket hook state (e.g., kqueue SO_LINGER tracking).
7480
[[no_unique_address]] typename Traits::stream_socket_hook hook_;
7581

76-
explicit reactor_stream_socket_impl(Service& svc) noexcept
77-
: reactor_stream_socket_impl::reactor_stream_socket(svc)
78-
{
79-
}
80-
8182
~reactor_stream_socket_impl() override = default;
8283

8384
std::error_code set_option(
@@ -124,16 +125,17 @@ class reactor_dgram_socket_impl
124125
ImplBase,
125126
Endpoint>
126127
{
128+
friend Derived;
127129
friend Service;
128130

129-
public:
130-
using impl_base_type = ImplBase;
131-
132131
explicit reactor_dgram_socket_impl(Service& svc) noexcept
133132
: reactor_dgram_socket_impl::reactor_datagram_socket(svc)
134133
{
135134
}
136135

136+
public:
137+
using impl_base_type = ImplBase;
138+
137139
~reactor_dgram_socket_impl() override = default;
138140
};
139141

@@ -162,16 +164,17 @@ class reactor_acceptor_impl
162164
AccImplBase,
163165
Endpoint>
164166
{
167+
friend Derived;
165168
friend Service;
166169

167-
public:
168-
using impl_base_type = AccImplBase;
169-
170170
explicit reactor_acceptor_impl(Service& svc) noexcept
171171
: reactor_acceptor_impl::reactor_acceptor(svc)
172172
{
173173
}
174174

175+
public:
176+
using impl_base_type = AccImplBase;
177+
175178
~reactor_acceptor_impl() override = default;
176179

177180
std::coroutine_handle<> accept(

include/boost/corosio/native/detail/reactor/reactor_socket_service.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class reactor_socket_service : public ServiceBase
3939
using state_type = reactor_service_state<Scheduler, Impl>;
4040

4141
protected:
42+
// NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility)
4243
explicit reactor_socket_service(capy::execution_context& ctx)
4344
: state_(
4445
std::make_unique<state_type>(

include/boost/corosio/native/detail/reactor/reactor_stream_socket.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class reactor_stream_socket
6868
friend Derived;
6969

7070
protected:
71+
// NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility)
7172
explicit reactor_stream_socket(Service& svc) noexcept : base_type(svc) {}
7273

7374
protected:

0 commit comments

Comments
 (0)