From f442e7c3aa320ac9c76b83c8c18af2339de1f942 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 30 Mar 2023 12:11:19 -0400 Subject: [PATCH] cpp-common/uuid-view: use string::operator[] instead of string::data to access internal buffer Using UuidView::string fails with: CXX ctf-ir.lo In file included from /home/smarchi/src/babeltrace/src/cpp-common/bt2/clock-class.hpp:20, from /home/smarchi/src/babeltrace/src/cpp-common/bt2/trace-ir.hpp:19, from /home/smarchi/src/babeltrace/src/plugins/ctf/common/src/metadata/ctf-ir.hpp:18, from /home/smarchi/src/babeltrace/src/plugins/ctf/common/src/metadata/ctf-ir.cpp:8: /home/smarchi/src/babeltrace/src/cpp-common/uuid-view.hpp: In member function 'std::string bt2_common::UuidView::str() const': /home/smarchi/src/babeltrace/src/cpp-common/uuid-view.hpp:57:38: error: invalid conversion from 'const char*' to 'char*' [-fpermissive] 57 | bt_uuid_to_str(_mUuid, s.data()); | ~~~~~~^~ | | | const char* In file included from /home/smarchi/src/babeltrace/src/plugins/ctf/common/src/metadata/ctf-ir.hpp:15: /home/smarchi/src/babeltrace/src/common/uuid.h:40:62: note: initializing argument 2 of 'void bt_uuid_to_str(const uint8_t*, char*)' 40 | BT_HIDDEN void bt_uuid_to_str(const bt_uuid_t uuid_in, char *str_out); | ~~~~~~^~~~~~~ This is because the data method only has a const version in C++11: https://en.cppreference.com/w/cpp/string/basic_string/data It therefore can't be used to modify the content of the string. Use operator[] instead. Change-Id: I3bd9c9756c4e79856a5f0f0c7d8fa14e19c1eadd Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/10805 Tested-by: jenkins CI-Build: Philippe Proulx Reviewed-by: Philippe Proulx --- src/cpp-common/uuid-view.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp-common/uuid-view.hpp b/src/cpp-common/uuid-view.hpp index 35b0b062..15becec0 100644 --- a/src/cpp-common/uuid-view.hpp +++ b/src/cpp-common/uuid-view.hpp @@ -40,7 +40,7 @@ public: std::string s; s.resize(BT_UUID_STR_LEN); - bt_uuid_to_str(_mUuid, s.data()); + bt_uuid_to_str(_mUuid, &s[0]); return s; } -- 2.34.1