Skip to content

Commit 5b72b3e

Browse files
committed
Fix dangling pointer warnings in test
1 parent 6bc257e commit 5b72b3e

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

sdk/test/trace/tracer_config_test.cc

+23-28
Original file line numberDiff line numberDiff line change
@@ -45,50 +45,45 @@ static std::pair<opentelemetry::nostd::string_view, opentelemetry::common::Attri
4545
static std::pair<opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue> attr3 = {
4646
"accept_third_attr", 3};
4747

48-
static instrumentation_scope::InstrumentationScope *test_scope_1 =
49-
std::move(instrumentation_scope::InstrumentationScope::Create("test_scope_1")).get();
50-
static instrumentation_scope::InstrumentationScope *test_scope_2 =
51-
std::move(instrumentation_scope::InstrumentationScope::Create("test_scope_2", "1.0")).get();
52-
static instrumentation_scope::InstrumentationScope *test_scope_3 =
53-
std::move(instrumentation_scope::InstrumentationScope::Create(
54-
"test_scope_3",
55-
"0",
56-
"https://opentelemetry.io/schemas/v1.18.0"))
57-
.get();
58-
static instrumentation_scope::InstrumentationScope *test_scope_4 =
59-
std::move(instrumentation_scope::InstrumentationScope::Create(
60-
"test_scope_4",
61-
"0",
62-
"https://opentelemetry.io/schemas/v1.18.0",
63-
{attr1}))
64-
.get();
65-
static instrumentation_scope::InstrumentationScope *test_scope_5 =
66-
std::move(instrumentation_scope::InstrumentationScope::Create(
67-
"test_scope_5",
68-
"0",
69-
"https://opentelemetry.io/schemas/v1.18.0",
70-
{attr1, attr2, attr3}))
71-
.get();
48+
static instrumentation_scope::InstrumentationScope test_scope_1 =
49+
*std::move(instrumentation_scope::InstrumentationScope::Create("test_scope_1"));
50+
static instrumentation_scope::InstrumentationScope test_scope_2 =
51+
*std::move(instrumentation_scope::InstrumentationScope::Create("test_scope_2", "1.0"));
52+
static instrumentation_scope::InstrumentationScope test_scope_3 =
53+
*std::move(instrumentation_scope::InstrumentationScope::Create(
54+
"test_scope_3",
55+
"0",
56+
"https://opentelemetry.io/schemas/v1.18.0"));
57+
static instrumentation_scope::InstrumentationScope test_scope_4 = *std::move(
58+
instrumentation_scope::InstrumentationScope::Create("test_scope_4",
59+
"0",
60+
"https://opentelemetry.io/schemas/v1.18.0",
61+
{attr1}));
62+
static instrumentation_scope::InstrumentationScope test_scope_5 = *std::move(
63+
instrumentation_scope::InstrumentationScope::Create("test_scope_5",
64+
"0",
65+
"https://opentelemetry.io/schemas/v1.18.0",
66+
{attr1, attr2, attr3}));
7267

73-
const std::array<instrumentation_scope::InstrumentationScope *, 5> instrumentation_scopes = {
68+
const std::array<instrumentation_scope::InstrumentationScope, 5> instrumentation_scopes = {
7469
test_scope_1, test_scope_2, test_scope_3, test_scope_4, test_scope_5,
7570
};
7671

7772
// Test fixture for VerifyDefaultConfiguratorBehavior
7873
class DefaultTracerConfiguratorTestFixture
79-
: public ::testing::TestWithParam<instrumentation_scope::InstrumentationScope *>
74+
: public ::testing::TestWithParam<instrumentation_scope::InstrumentationScope>
8075
{};
8176

8277
// verifies that the default configurator always returns the default tracer config
8378
TEST_P(DefaultTracerConfiguratorTestFixture, VerifyDefaultConfiguratorBehavior)
8479
{
85-
instrumentation_scope::InstrumentationScope *scope = GetParam();
80+
instrumentation_scope::InstrumentationScope scope = GetParam();
8681
instrumentation_scope::ScopeConfigurator<trace_sdk::TracerConfig> default_configurator =
8782
instrumentation_scope::ScopeConfigurator<trace_sdk::TracerConfig>::Builder(
8883
trace_sdk::TracerConfig::Default())
8984
.Build();
9085

91-
ASSERT_EQ(default_configurator.ComputeConfig(*scope), trace_sdk::TracerConfig::Default());
86+
ASSERT_EQ(default_configurator.ComputeConfig(scope), trace_sdk::TracerConfig::Default());
9287
}
9388

9489
INSTANTIATE_TEST_SUITE_P(InstrumentationScopes,

0 commit comments

Comments
 (0)