summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2024-09-11 18:30:40 +0000
committerDavid Kalnischkies <david@kalnischkies.de>2024-11-22 12:11:13 +0000
commitbaf93ab433283bf836848035afa31690b30868a5 (patch)
tree6f435a693093f155f8146d3627b59a4d79e298b1
parentfa19a9ddbdddeaed44480ce7dade11d526336435 (diff)
Fix expired std::string usage in APT::StringView testcase
The anonymous std::string we were using here to create the view expires after the construction of the view and so the gcc warning | warning: ‘<anonymous>’ may be used uninitialized [-Wmaybe-uninitialized] is correct in that the memory we are pointing to is potentially overridden/reused already, if a bit roundabout in saying so.
-rw-r--r--test/libapt/stringview_test.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/test/libapt/stringview_test.cc b/test/libapt/stringview_test.cc
index 5abb7a8e1..5b82a0da5 100644
--- a/test/libapt/stringview_test.cc
+++ b/test/libapt/stringview_test.cc
@@ -35,7 +35,8 @@ TEST(StringViewTest,FooString)
static_assert( 3 == defString.length(), "def right size");
EXPECT_EQ(0, defString.to_string().compare(0, defString.length(), defString.data(), 3));
- APT::StringView strString{std::string{"foo"}};
+ std::string strstr{"foo"};
+ APT::StringView strString{strstr};
EXPECT_EQ(3u, strString.length());
EXPECT_EQ(0, strString.to_string().compare(0, strString.length(), strString.data(), 3));