Skip to content

Commit 481649a

Browse files
committed
fixed shared_ptr constructor from unique_ptr and context formatting
- Fixed formatting issues in `context.h` - Adjusted `shared_ptr` construction from `unique_ptr` - Added test for move construction from `nostd::unique_ptr`
1 parent 000b21e commit 481649a

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

api/include/opentelemetry/context/context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Context
105105
if (iter == std::end(keys_and_vals))
106106
return;
107107
auto *node = this;
108-
*node = DataList(iter->first, iter->second);
108+
*node = DataList(iter->first, iter->second);
109109
for (++iter; iter != std::end(keys_and_vals); ++iter)
110110
{
111111
node->next_ = nostd::shared_ptr<DataList>(new DataList(iter->first, iter->second));
@@ -116,7 +116,7 @@ class Context
116116
// Builds a data list with just a key and value, so it will just be the head
117117
// and returns that head.
118118
DataList(nostd::string_view key, const ContextValue &value)
119-
: key_(key.begin(), key.end()), value_(value)
119+
: key_(key.begin(), key.end()), value_(value)
120120
{}
121121
};
122122

api/include/opentelemetry/nostd/shared_ptr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class shared_ptr
102102

103103
shared_ptr(unique_ptr<T> &&other) noexcept
104104
{
105-
std::shared_ptr<T> ptr_(std::move(other));
105+
std::shared_ptr<T> ptr_(other.release());
106106
new (buffer_.data) shared_ptr_wrapper{std::move(ptr_)};
107107
}
108108

api/test/nostd/shared_ptr_test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ TEST(SharedPtrTest, MoveConstructionFromStdSharedPtr)
9696
EXPECT_EQ(ptr2.get(), value);
9797
}
9898

99+
TEST(SharedPtrTest, MoveConstructionFromNoStdUniquePtr)
100+
{
101+
opentelemetry::nostd::unique_ptr<int> value(new int{123});
102+
auto p = value.get();
103+
shared_ptr<int> ptr{std::move(value)};
104+
EXPECT_EQ(value.get(), nullptr); // NOLINT
105+
EXPECT_EQ(ptr.get(), p);
106+
}
107+
99108
TEST(SharedPtrTest, Destruction)
100109
{
101110
bool was_destructed;

0 commit comments

Comments
 (0)