Skip to content

Commit 82fb2ee

Browse files
committed
fix(fault_manager): explicit ctor for LockedSubscriptionGuard (C++20 aggregate)
Rolling's gcc 14 / libstdc++ enforces the C++20 wording of [dcl.init.aggr] that disqualifies a class as an aggregate when it has any user-declared constructors - including ``= delete`` ones (rule tightened from C++17's "user-provided" to C++20's "user-declared"). Even with CMAKE_CXX_STANDARD=17 set, the libstdc++ headers/checks behave as C++20 on rolling, breaking ``LockedSubscriptionGuard{&mtx, sub, cg}`` because the only candidates are the deleted copy/move constructors. Add an explicit 3-arg constructor so brace-init resolves to direct-init regardless of aggregate semantics across distros (Jazzy/Humble C++17 and Rolling effective-C++20). Reproduces locally with ``g++ -std=c++20``.
1 parent d675c07 commit 82fb2ee

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/ros2_medkit_fault_manager/src/snapshot_capture.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ struct LockedSubscriptionGuard {
4040
rclcpp::GenericSubscription::SharedPtr subscription;
4141
rclcpp::CallbackGroup::SharedPtr callback_group;
4242

43+
// Explicit constructor instead of relying on aggregate initialization:
44+
// C++20 [dcl.init.aggr] disqualifies a class as an aggregate if it has
45+
// any user-declared constructors, including ``= delete`` ones (the rule
46+
// tightened from "user-provided" in C++17 to "user-declared" in C++20).
47+
// Rolling's gcc 14 / libstdc++ enforces the C++20 wording even when
48+
// CMAKE_CXX_STANDARD is 17, so brace-init ``LockedSubscriptionGuard{
49+
// &mtx, sub, cg}`` would fail to find a matching constructor on rolling.
50+
// An explicit constructor sidesteps the aggregate-init rules entirely.
51+
LockedSubscriptionGuard(std::mutex * m, rclcpp::GenericSubscription::SharedPtr s, rclcpp::CallbackGroup::SharedPtr cg)
52+
: mtx(m), subscription(std::move(s)), callback_group(std::move(cg)) {
53+
}
54+
4355
~LockedSubscriptionGuard() {
4456
if (!subscription && !callback_group) {
4557
return;

0 commit comments

Comments
 (0)