cpp-common/bt2: add const_cast when setting user data
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 13 Feb 2024 16:00:46 +0000 (11:00 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 19 Feb 2024 18:10:15 +0000 (13:10 -0500)
If the user data type is specified as a const type,
`static_cast<void *>` will not work.  Fix that by doing a static_cast to
`const void *` then a const_cast to `void *`.

Change-Id: Ic39c9c25da1899defe4edf8c8e800297fbf2fb2d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11799
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/cpp-common/bt2/self-component-port.hpp
src/cpp-common/bt2/self-message-iterator.hpp

index 2551064ecbd1cdcbf17e53abc95343ac2229ac4f..5b34abfd1d3fbf486c552bd632e960d0f4a0186e 100644 (file)
@@ -102,7 +102,8 @@ public:
     template <typename T>
     void data(T& obj) const noexcept
     {
-        bt_self_component_set_data(this->libObjPtr(), static_cast<void *>(&obj));
+        bt_self_component_set_data(this->libObjPtr(),
+                                   const_cast<void *>(static_cast<const void *>(&obj)));
     }
 
     bt2::TraceClass::Shared createTraceClass() const
@@ -148,7 +149,8 @@ protected:
     {
         LibPortT *libPortPtr;
 
-        const auto status = func(this->libObjPtr(), name, static_cast<void *>(data), &libPortPtr);
+        const auto status = func(this->libObjPtr(), name,
+                                 const_cast<void *>(static_cast<const void *>(data)), &libPortPtr);
 
         switch (status) {
         case BT_SELF_COMPONENT_ADD_PORT_STATUS_OK:
index e333cb1a41587d62990ce0f4807198c0f551cf9c..4460fe27e79c422cc90f9f222147a4c48d96ae2b 100644 (file)
@@ -69,7 +69,8 @@ public:
     template <typename T>
     void data(T& obj) const noexcept
     {
-        bt_self_message_iterator_set_data(this->libObjPtr(), static_cast<void *>(&obj));
+        bt_self_message_iterator_set_data(this->libObjPtr(),
+                                          const_cast<void *>(static_cast<const void *>(&obj)));
     }
 
     bt2::StreamBeginningMessage::Shared
This page took 0.024762 seconds and 4 git commands to generate.