Skip to content

Commit b41fe0c

Browse files
committed
node interfaces: fix unintentionally invoked copy constructor by explicitly getting a reference using a lambda instead of a conditional operator where the type is NodeT instead of NodeT &
Signed-off-by: Fabian Hirmann <f.hirmann@arti-robots.com>
1 parent 9933fba commit b41fe0c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

rclcpp/include/rclcpp/node_interfaces/node_interfaces.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ class NodeInterfaces
150150
/// NodeT::SharedPtr Constructor
151151
template<typename NodeT>
152152
NodeInterfaces(std::shared_ptr<NodeT> node) // NOLINT(runtime/explicit)
153-
: NodeInterfaces(node ? *node : throw std::invalid_argument("given node pointer is nullptr"))
153+
: NodeInterfaces(
154+
[&]() -> NodeT & {
155+
if (!node) {
156+
throw std::invalid_argument("given node pointer is nullptr");
157+
}
158+
return *node;
159+
}())
154160
{}
155161

156162
explicit NodeInterfaces(std::shared_ptr<InterfaceTs>... args)

0 commit comments

Comments
 (0)