From 1c11db0b68aac8994a92d8c5291eec1ac5ecd82c Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 13 Mar 2024 00:27:54 -0400 Subject: [PATCH] cpp-common/bt2: use universal reference for `Graph::addComponent()` initialization data I noticed it was not possible to pass data to `Graph::addComponent` using a temporary object: graph->addComponent(*srcCompCls, "source-1", TestSourceData {}); My understanding of it is that the compiler does not consider the overload with the `InitDataT&` parameter for this, because the temporary object can't bind to the lvalue reference. Change these methods to take forwarding references instead. Change-Id: Icc80239812c325b777ed83e8634302a0c9d72f14 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/12049 Reviewed-by: Philippe Proulx Tested-by: jenkins --- src/cpp-common/bt2/graph.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cpp-common/bt2/graph.hpp b/src/cpp-common/bt2/graph.hpp index c1c6ad09..0927cd30 100644 --- a/src/cpp-common/bt2/graph.hpp +++ b/src/cpp-common/bt2/graph.hpp @@ -66,7 +66,7 @@ public: template ConstSourceComponent addComponent(const ConstSourceComponentClass componentClass, - const bt2c::CStringView name, InitDataT& initData, + const bt2c::CStringView name, InitDataT&& initData, const OptionalBorrowedObject params = {}, const LoggingLevel loggingLevel = LoggingLevel::NONE) const { @@ -87,7 +87,7 @@ public: template ConstFilterComponent addComponent(const ConstFilterComponentClass componentClass, - const bt2c::CStringView name, InitDataT& initData, + const bt2c::CStringView name, InitDataT&& initData, const OptionalBorrowedObject params = {}, const LoggingLevel loggingLevel = LoggingLevel::NONE) const { @@ -108,7 +108,7 @@ public: template ConstSinkComponent addComponent(const ConstSinkComponentClass componentClass, - const bt2c::CStringView name, InitDataT& initData, + const bt2c::CStringView name, InitDataT&& initData, const OptionalBorrowedObject params = {}, const LoggingLevel loggingLevel = LoggingLevel::NONE) const { -- 2.34.1