Skip to content

Commit 923bc47

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 923bc47

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <vector>
1010

1111
#include "opentelemetry/nostd/shared_ptr.h"
12+
#include "opentelemetry/nostd/unique_ptr.h"
1213

1314
using opentelemetry::nostd::shared_ptr;
1415

@@ -96,6 +97,15 @@ TEST(SharedPtrTest, MoveConstructionFromStdSharedPtr)
9697
EXPECT_EQ(ptr2.get(), value);
9798
}
9899

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

0 commit comments

Comments
 (0)