diff --git a/CMakeLists.txt b/CMakeLists.txt index 48f2072667..5464f76d1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -488,6 +488,8 @@ if(OTELCPP_MAINTAINER_MODE) $<$,CXX>:-Woverloaded-virtual>) add_compile_options( $<$,CXX>:-Wsuggest-override>) + add_compile_options( + $<$,CXX>:-Wold-style-cast>) # C and C++ add_compile_options(-Wcast-qual) @@ -527,6 +529,7 @@ if(OTELCPP_MAINTAINER_MODE) add_compile_options(-Wundef) add_compile_options(-Wundefined-reinterpret-cast) add_compile_options(-Wvla) + add_compile_options(-Wold-style-cast) endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") message("Building with msvc in maintainer mode.") diff --git a/api/include/opentelemetry/trace/span_context.h b/api/include/opentelemetry/trace/span_context.h index 944bdc0221..5fcab6e7ed 100644 --- a/api/include/opentelemetry/trace/span_context.h +++ b/api/include/opentelemetry/trace/span_context.h @@ -30,7 +30,7 @@ class SpanContext final SpanContext(bool sampled_flag, bool is_remote) noexcept : trace_id_(), span_id_(), - trace_flags_(trace::TraceFlags((uint8_t)sampled_flag)), + trace_flags_(trace::TraceFlags(static_cast(sampled_flag))), is_remote_(is_remote), trace_state_(TraceState::GetDefault()) {} diff --git a/api/test/context/context_test.cc b/api/test/context/context_test.cc index 975e11f8c4..764dac6477 100644 --- a/api/test/context/context_test.cc +++ b/api/test/context/context_test.cc @@ -12,15 +12,15 @@ using namespace opentelemetry; // Tests that the context constructor accepts an std::map. TEST(ContextTest, ContextIterableAcceptsMap) { - std::map map_test = {{"test_key", (int64_t)123}}; + std::map map_test = {{"test_key", static_cast(123)}}; context::Context test_context = context::Context(map_test); } // Tests that the GetValue method returns the expected value. TEST(ContextTest, ContextGetValueReturnsExpectedValue) { - std::map map_test = {{"test_key", (int64_t)123}, - {"foo_key", (int64_t)456}}; + std::map map_test = {{"test_key", static_cast(123)}, + {"foo_key", static_cast(456)}}; const context::Context test_context = context::Context(map_test); EXPECT_EQ(nostd::get(test_context.GetValue("test_key")), 123); EXPECT_EQ(nostd::get(test_context.GetValue("foo_key")), 456); @@ -29,8 +29,9 @@ TEST(ContextTest, ContextGetValueReturnsExpectedValue) // Tests that the SetValues method accepts an std::map. TEST(ContextTest, ContextSetValuesAcceptsMap) { - std::map map_test = {{"test_key", (int64_t)123}}; - std::map map_test_write = {{"foo_key", (int64_t)456}}; + std::map map_test = {{"test_key", static_cast(123)}}; + std::map map_test_write = { + {"foo_key", static_cast(456)}}; context::Context test_context = context::Context(map_test); context::Context foo_context = test_context.SetValues(map_test_write); @@ -44,7 +45,7 @@ TEST(ContextTest, ContextSetValuesAcceptsMap) TEST(ContextTest, ContextSetValuesAcceptsStringViewContextValue) { nostd::string_view string_view_test = "string_view"; - context::ContextValue context_value_test = (int64_t)123; + context::ContextValue context_value_test = static_cast(123); context::Context test_context = context::Context(string_view_test, context_value_test); context::Context foo_context = test_context.SetValue(string_view_test, context_value_test); @@ -56,10 +57,10 @@ TEST(ContextTest, ContextSetValuesAcceptsStringViewContextValue) // written to it. TEST(ContextTest, ContextImmutability) { - std::map map_test = {{"test_key", (int64_t)123}}; + std::map map_test = {{"test_key", static_cast(123)}}; context::Context context_test = context::Context(map_test); - context::Context context_foo = context_test.SetValue("foo_key", (int64_t)456); + context::Context context_foo = context_test.SetValue("foo_key", static_cast(456)); EXPECT_FALSE(nostd::holds_alternative(context_test.GetValue("foo_key"))); } @@ -67,10 +68,10 @@ TEST(ContextTest, ContextImmutability) // Tests that writing the same to a context overwrites the original value. TEST(ContextTest, ContextKeyOverwrite) { - std::map map_test = {{"test_key", (int64_t)123}}; + std::map map_test = {{"test_key", static_cast(123)}}; context::Context context_test = context::Context(map_test); - context::Context context_foo = context_test.SetValue("test_key", (int64_t)456); + context::Context context_foo = context_test.SetValue("test_key", static_cast(456)); EXPECT_EQ(nostd::get(context_foo.GetValue("test_key")), 456); } @@ -81,8 +82,8 @@ TEST(ContextTest, ContextInheritance) { using M = std::map; - M m1 = {{"test_key", (int64_t)123}, {"foo_key", (int64_t)321}}; - M m2 = {{"other_key", (int64_t)789}, {"another_key", (int64_t)987}}; + M m1 = {{"test_key", static_cast(123)}, {"foo_key", static_cast(321)}}; + M m2 = {{"other_key", static_cast(789)}, {"another_key", static_cast(987)}}; context::Context test_context = context::Context(m1); context::Context foo_context = test_context.SetValues(m2); @@ -100,7 +101,9 @@ TEST(ContextTest, ContextInheritance) TEST(ContextTest, ContextCopyOperator) { std::map test_map = { - {"test_key", (int64_t)123}, {"foo_key", (int64_t)456}, {"other_key", (int64_t)789}}; + {"test_key", static_cast(123)}, + {"foo_key", static_cast(456)}, + {"other_key", static_cast(789)}}; context::Context test_context = context::Context(test_map); context::Context copied_context = test_context; @@ -121,7 +124,7 @@ TEST(ContextTest, ContextEmptyMap) // false if not. TEST(ContextTest, ContextHasKey) { - std::map map_test = {{"test_key", (int64_t)123}}; + std::map map_test = {{"test_key", static_cast(123)}}; const context::Context context_test = context::Context(map_test); EXPECT_TRUE(context_test.HasKey("test_key")); EXPECT_FALSE(context_test.HasKey("foo_key")); @@ -130,7 +133,7 @@ TEST(ContextTest, ContextHasKey) // Tests that a copied context returns true when compared TEST(ContextTest, ContextCopyCompare) { - std::map map_test = {{"test_key", (int64_t)123}}; + std::map map_test = {{"test_key", static_cast(123)}}; context::Context context_test = context::Context(map_test); context::Context copied_test = context_test; EXPECT_TRUE(context_test == copied_test); @@ -139,8 +142,8 @@ TEST(ContextTest, ContextCopyCompare) // Tests that two differently constructed contexts return false when compared TEST(ContextTest, ContextDiffCompare) { - std::map map_test = {{"test_key", (int64_t)123}}; - std::map map_foo = {{"foo_key", (int64_t)123}}; + std::map map_test = {{"test_key", static_cast(123)}}; + std::map map_foo = {{"foo_key", static_cast(123)}}; context::Context context_test = context::Context(map_test); context::Context foo_test = context::Context(map_foo); EXPECT_FALSE(context_test == foo_test); diff --git a/api/test/context/runtime_context_test.cc b/api/test/context/runtime_context_test.cc index 40b11dde95..c2ec732fe0 100644 --- a/api/test/context/runtime_context_test.cc +++ b/api/test/context/runtime_context_test.cc @@ -14,7 +14,7 @@ using namespace opentelemetry; // Tests that GetCurrent returns the current context TEST(RuntimeContextTest, GetCurrent) { - std::map map_test = {{"test_key", (int64_t)123}}; + std::map map_test = {{"test_key", static_cast(123)}}; context::Context test_context = context::Context(map_test); auto old_context = context::RuntimeContext::Attach(test_context); EXPECT_EQ(context::RuntimeContext::GetCurrent(), test_context); @@ -23,7 +23,7 @@ TEST(RuntimeContextTest, GetCurrent) // Tests that detach resets the context to the previous context TEST(RuntimeContextTest, Detach) { - std::map map_test = {{"test_key", (int64_t)123}}; + std::map map_test = {{"test_key", static_cast(123)}}; context::Context test_context = context::Context(map_test); context::Context foo_context = context::Context(map_test); @@ -38,7 +38,7 @@ TEST(RuntimeContextTest, Detach) // Tests that detach returns false when the wrong context is provided TEST(RuntimeContextTest, DetachWrongContext) { - std::map map_test = {{"test_key", (int64_t)123}}; + std::map map_test = {{"test_key", static_cast(123)}}; context::Context test_context = context::Context(map_test); auto test_context_token = context::RuntimeContext::Attach(test_context); EXPECT_TRUE(context::RuntimeContext::Detach(*test_context_token)); @@ -48,7 +48,7 @@ TEST(RuntimeContextTest, DetachWrongContext) // Tests that the ThreadLocalContext can handle three attached contexts TEST(RuntimeContextTest, ThreeAttachDetach) { - std::map map_test = {{"test_key", (int64_t)123}}; + std::map map_test = {{"test_key", static_cast(123)}}; context::Context test_context = context::Context(map_test); context::Context foo_context = context::Context(map_test); context::Context other_context = context::Context(map_test); @@ -66,9 +66,10 @@ TEST(RuntimeContextTest, ThreeAttachDetach) // RuntimeContext::SetValue method. TEST(RuntimeContextTest, SetValueRuntimeContext) { - context::Context foo_context = context::Context("foo_key", (int64_t)596); - auto old_context_token = context::RuntimeContext::Attach(foo_context); - context::Context test_context = context::RuntimeContext::SetValue("test_key", (int64_t)123); + context::Context foo_context = context::Context("foo_key", static_cast(596)); + auto old_context_token = context::RuntimeContext::Attach(foo_context); + context::Context test_context = + context::RuntimeContext::SetValue("test_key", static_cast(123)); EXPECT_EQ(nostd::get(test_context.GetValue("test_key")), 123); EXPECT_EQ(nostd::get(test_context.GetValue("foo_key")), 596); } @@ -78,9 +79,9 @@ TEST(RuntimeContextTest, SetValueRuntimeContext) // RuntimeContext::SetValue method. TEST(RuntimeContextTest, SetValueOtherContext) { - context::Context foo_context = context::Context("foo_key", (int64_t)596); + context::Context foo_context = context::Context("foo_key", static_cast(596)); context::Context test_context = - context::RuntimeContext::SetValue("test_key", (int64_t)123, &foo_context); + context::RuntimeContext::SetValue("test_key", static_cast(123), &foo_context); EXPECT_EQ(nostd::get(test_context.GetValue("test_key")), 123); EXPECT_EQ(nostd::get(test_context.GetValue("foo_key")), 596); } @@ -89,7 +90,7 @@ TEST(RuntimeContextTest, SetValueOtherContext) // passed in string and the current Runtime Context TEST(RuntimeContextTest, GetValueRuntimeContext) { - context::Context foo_context = context::Context("foo_key", (int64_t)596); + context::Context foo_context = context::Context("foo_key", static_cast(596)); auto old_context_token = context::RuntimeContext::Attach(foo_context); EXPECT_EQ(nostd::get(context::RuntimeContext::GetValue("foo_key")), 596); } @@ -98,7 +99,7 @@ TEST(RuntimeContextTest, GetValueRuntimeContext) // passed in string and the passed in context TEST(RuntimeContextTest, GetValueOtherContext) { - context::Context foo_context = context::Context("foo_key", (int64_t)596); + context::Context foo_context = context::Context("foo_key", static_cast(596)); EXPECT_EQ(nostd::get(context::RuntimeContext::GetValue("foo_key", &foo_context)), 596); } @@ -114,7 +115,7 @@ TEST(RuntimeContextTest, DetachOutOfOrder) std::vector contexts; for (auto i : indices) { - contexts.push_back(context::Context("index", (int64_t)i)); + contexts.push_back(context::Context("index", static_cast(i))); } do diff --git a/api/test/nostd/span_test.cc b/api/test/nostd/span_test.cc index 5c13ee590e..17427a249a 100644 --- a/api/test/nostd/span_test.cc +++ b/api/test/nostd/span_test.cc @@ -167,10 +167,10 @@ TEST(SpanTest, Iteration) std::array array = {1, 2, 3}; span s1{array.data(), array.size()}; - EXPECT_EQ(std::distance(s1.begin(), s1.end()), (ptrdiff_t)array.size()); + EXPECT_EQ(std::distance(s1.begin(), s1.end()), static_cast(array.size())); EXPECT_TRUE(std::equal(s1.begin(), s1.end(), array.begin())); span s2{array.data(), array.size()}; - EXPECT_EQ(std::distance(s2.begin(), s2.end()), (ptrdiff_t)array.size()); + EXPECT_EQ(std::distance(s2.begin(), s2.end()), static_cast(array.size())); EXPECT_TRUE(std::equal(s2.begin(), s2.end(), array.begin())); } diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index 187e26f2b4..0973a1427f 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -55,7 +55,7 @@ void do_something() void *component_g = dlopen("libcomponent_g.so", RTLD_NOW); EXPECT_NE(component_g, nullptr); - auto *func_g = (void (*)())dlsym(component_g, "do_something_in_g"); + auto *func_g = reinterpret_cast(dlsym(component_g, "do_something_in_g")); EXPECT_NE(func_g, nullptr); (*func_g)(); @@ -67,7 +67,7 @@ void do_something() void *component_h = dlopen("libcomponent_h.so", RTLD_NOW); EXPECT_NE(component_h, nullptr); - auto *func_h = (void (*)())dlsym(component_h, "do_something_in_h"); + auto *func_h = reinterpret_cast(dlsym(component_h, "do_something_in_h")); EXPECT_NE(func_h, nullptr); (*func_h)(); diff --git a/examples/batch/main.cc b/examples/batch/main.cc index 0e05c1b700..ece864001a 100644 --- a/examples/batch/main.cc +++ b/examples/batch/main.cc @@ -38,7 +38,8 @@ void InitTracer() // We export `kNumSpans` after every `schedule_delay_millis` milliseconds. options.max_export_batch_size = kNumSpans; - resource::ResourceAttributes attributes = {{"service", "test_service"}, {"version", (uint32_t)1}}; + resource::ResourceAttributes attributes = {{"service", "test_service"}, + {"version", static_cast(1)}}; auto resource = resource::Resource::Create(attributes); auto processor = trace_sdk::BatchSpanProcessorFactory::Create(std::move(exporter), options); diff --git a/examples/http/client.cc b/examples/http/client.cc index 433f51a64f..3a8486f55f 100644 --- a/examples/http/client.cc +++ b/examples/http/client.cc @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) // The port the validation service listens to can be specified via the command line. if (argc > 1) { - port = (uint16_t)(atoi(argv[1])); + port = static_cast(atoi(argv[1])); } else { diff --git a/examples/http/server.cc b/examples/http/server.cc index c2d7a2c5a3..3dbdae8512 100644 --- a/examples/http/server.cc +++ b/examples/http/server.cc @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) // The port the validation service listens to can be specified via the command line. if (argc > 1) { - server_port = (uint16_t)atoi(argv[1]); + server_port = static_cast(atoi(argv[1])); } HttpServer http_server(server_name, server_port); diff --git a/exporters/ostream/test/ostream_metric_test.cc b/exporters/ostream/test/ostream_metric_test.cc index 17fbcb5880..bd221fa1b7 100644 --- a/exporters/ostream/test/ostream_metric_test.cc +++ b/exporters/ostream/test/ostream_metric_test.cc @@ -109,7 +109,7 @@ TEST(OStreamMetricsExporter, ExportHistogramPointData) histogram_point_data2.boundaries_ = std::vector{10.0, 20.0, 30.0}; histogram_point_data2.count_ = 3; histogram_point_data2.counts_ = {200, 300, 400, 500}; - histogram_point_data2.sum_ = (int64_t)900; + histogram_point_data2.sum_ = static_cast(900); metric_sdk::ResourceMetrics data; auto resource = opentelemetry::sdk::resource::Resource::Create( opentelemetry::sdk::resource::ResourceAttributes{}); @@ -191,7 +191,7 @@ TEST(OStreamMetricsExporter, ExportLastValuePointData) last_value_point_data.is_lastvalue_valid_ = true; last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; metric_sdk::LastValuePointData last_value_point_data2{}; - last_value_point_data2.value_ = (int64_t)20; + last_value_point_data2.value_ = static_cast(20); last_value_point_data2.is_lastvalue_valid_ = true; last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{}; metric_sdk::MetricData metric_data{ diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index 5812dddc25..b230f68d19 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -308,7 +308,7 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test last_value_point_data.is_lastvalue_valid_ = true; last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; opentelemetry::sdk::metrics::LastValuePointData last_value_point_data2{}; - last_value_point_data2.value_ = (int64_t)20; + last_value_point_data2.value_ = static_cast(20); last_value_point_data2.is_lastvalue_valid_ = true; last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{}; opentelemetry::sdk::metrics::MetricData metric_data{ @@ -404,7 +404,7 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test last_value_point_data.is_lastvalue_valid_ = true; last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; opentelemetry::sdk::metrics::LastValuePointData last_value_point_data2{}; - last_value_point_data2.value_ = (int64_t)20; + last_value_point_data2.value_ = static_cast(20); last_value_point_data2.is_lastvalue_valid_ = true; last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{}; opentelemetry::sdk::metrics::MetricData metric_data{ @@ -504,7 +504,7 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test histogram_point_data2.boundaries_ = {10.0, 20.0, 30.0}; histogram_point_data2.count_ = 3; histogram_point_data2.counts_ = {200, 300, 400, 500}; - histogram_point_data2.sum_ = (int64_t)900; + histogram_point_data2.sum_ = static_cast(900); opentelemetry::sdk::metrics::MetricData metric_data{ opentelemetry::sdk::metrics::InstrumentDescriptor{ @@ -639,7 +639,7 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test histogram_point_data2.boundaries_ = {10.0, 20.0, 30.0}; histogram_point_data2.count_ = 3; histogram_point_data2.counts_ = {200, 300, 400, 500}; - histogram_point_data2.sum_ = (int64_t)900; + histogram_point_data2.sum_ = static_cast(900); opentelemetry::sdk::metrics::MetricData metric_data{ opentelemetry::sdk::metrics::InstrumentDescriptor{ diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 1e0d018011..68d8586bcc 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -56,7 +56,7 @@ inline std::string Sanitize(std::string name, const T &valid) constexpr const auto replacement_dup = '='; bool has_dup = false; - for (int i = 0; i < (int)name.size(); ++i) + for (int i = 0; i < static_cast(name.size()); ++i) { if (valid(i, name[i]) && name[i] != replacement) { @@ -172,8 +172,9 @@ std::vector PrometheusExporterUtils::TranslateT { sum = static_cast(nostd::get(histogram_point_data.sum_)); } - SetData(std::vector{sum, (double)histogram_point_data.count_}, boundaries, counts, - point_data_attr.attributes, scope, time, &metric_family, data.resource_); + SetData(std::vector{sum, static_cast(histogram_point_data.count_)}, + boundaries, counts, point_data_attr.attributes, scope, time, &metric_family, + data.resource_); } else if (type == prometheus_client::MetricType::Gauge) { @@ -258,7 +259,7 @@ std::string PrometheusExporterUtils::SanitizeNames(std::string name) }; bool has_dup = false; - for (int i = 0; i < (int)name.size(); ++i) + for (int i = 0; i < static_cast(name.size()); ++i) { if (valid(i, name[i])) { diff --git a/exporters/prometheus/test/prometheus_test_helper.h b/exporters/prometheus/test/prometheus_test_helper.h index d42f66c6eb..b1aaf70d8c 100644 --- a/exporters/prometheus/test/prometheus_test_helper.h +++ b/exporters/prometheus/test/prometheus_test_helper.h @@ -58,7 +58,7 @@ struct TestDataPoints histogram_point_data2.boundaries_ = {10.0, 20.0, 30.0}; histogram_point_data2.count_ = 3; histogram_point_data2.counts_ = {200, 300, 400, 500}; - histogram_point_data2.sum_ = (int64_t)900; + histogram_point_data2.sum_ = static_cast(900); metric_sdk::ResourceMetrics data; data.resource_ = &resource; metric_sdk::MetricData metric_data{ @@ -84,7 +84,7 @@ struct TestDataPoints last_value_point_data.is_lastvalue_valid_ = true; last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; metric_sdk::LastValuePointData last_value_point_data2{}; - last_value_point_data2.value_ = (int64_t)20; + last_value_point_data2.value_ = static_cast(20); last_value_point_data2.is_lastvalue_valid_ = true; last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{}; metric_sdk::MetricData metric_data{ diff --git a/ext/src/http/client/curl/http_operation_curl.cc b/ext/src/http/client/curl/http_operation_curl.cc index f24d3fa53b..3b8e53af5e 100644 --- a/ext/src/http/client/curl/http_operation_curl.cc +++ b/ext/src/http/client/curl/http_operation_curl.cc @@ -60,7 +60,7 @@ size_t HttpOperation::WriteVectorHeaderCallback(void *ptr, size_t size, size_t n return 0; } - const unsigned char *begin = (unsigned char *)(ptr); + const unsigned char *begin = static_cast(ptr); const unsigned char *end = begin + size * nmemb; self->response_headers_.insert(self->response_headers_.end(), begin, end); @@ -90,7 +90,7 @@ size_t HttpOperation::WriteVectorBodyCallback(void *ptr, size_t size, size_t nme return 0; } - const unsigned char *begin = (unsigned char *)(ptr); + const unsigned char *begin = static_cast(ptr); const unsigned char *end = begin + size * nmemb; self->response_body_.insert(self->response_body_.end(), begin, end); @@ -810,7 +810,7 @@ CURLcode HttpOperation::Setup() if (ssl_options_.ssl_insecure_skip_verify) { /* 6 - DO NOT ENFORCE VERIFICATION, This is not secure. */ - rc = SetCurlLongOption(CURLOPT_USE_SSL, (long)CURLUSESSL_NONE); + rc = SetCurlLongOption(CURLOPT_USE_SSL, static_cast(CURLUSESSL_NONE)); if (rc != CURLE_OK) { return rc; @@ -831,7 +831,7 @@ CURLcode HttpOperation::Setup() else { /* 6 - ENFORCE VERIFICATION */ - rc = SetCurlLongOption(CURLOPT_USE_SSL, (long)CURLUSESSL_ALL); + rc = SetCurlLongOption(CURLOPT_USE_SSL, static_cast(CURLUSESSL_ALL)); if (rc != CURLE_OK) { return rc; @@ -932,13 +932,14 @@ CURLcode HttpOperation::Setup() return rc; } - rc = SetCurlPtrOption(CURLOPT_WRITEFUNCTION, (void *)&HttpOperation::WriteMemoryCallback); + rc = SetCurlPtrOption(CURLOPT_WRITEFUNCTION, + reinterpret_cast(&HttpOperation::WriteMemoryCallback)); if (rc != CURLE_OK) { return rc; } - rc = SetCurlPtrOption(CURLOPT_WRITEDATA, (void *)this); + rc = SetCurlPtrOption(CURLOPT_WRITEDATA, static_cast(this)); if (rc != CURLE_OK) { return rc; @@ -946,26 +947,27 @@ CURLcode HttpOperation::Setup() } else { - rc = SetCurlPtrOption(CURLOPT_WRITEFUNCTION, (void *)&HttpOperation::WriteVectorBodyCallback); + rc = SetCurlPtrOption(CURLOPT_WRITEFUNCTION, + reinterpret_cast(&HttpOperation::WriteVectorBodyCallback)); if (rc != CURLE_OK) { return rc; } - rc = SetCurlPtrOption(CURLOPT_WRITEDATA, (void *)this); + rc = SetCurlPtrOption(CURLOPT_WRITEDATA, static_cast(this)); if (rc != CURLE_OK) { return rc; } - rc = - SetCurlPtrOption(CURLOPT_HEADERFUNCTION, (void *)&HttpOperation::WriteVectorHeaderCallback); + rc = SetCurlPtrOption(CURLOPT_HEADERFUNCTION, + reinterpret_cast(&HttpOperation::WriteVectorHeaderCallback)); if (rc != CURLE_OK) { return rc; } - rc = SetCurlPtrOption(CURLOPT_HEADERDATA, (void *)this); + rc = SetCurlPtrOption(CURLOPT_HEADERDATA, static_cast(this)); if (rc != CURLE_OK) { return rc; @@ -996,13 +998,14 @@ CURLcode HttpOperation::Setup() return rc; } - rc = SetCurlPtrOption(CURLOPT_READFUNCTION, (void *)&HttpOperation::ReadMemoryCallback); + rc = SetCurlPtrOption(CURLOPT_READFUNCTION, + reinterpret_cast(&HttpOperation::ReadMemoryCallback)); if (rc != CURLE_OK) { return rc; } - rc = SetCurlPtrOption(CURLOPT_READDATA, (void *)this); + rc = SetCurlPtrOption(CURLOPT_READDATA, static_cast(this)); if (rc != CURLE_OK) { return rc; @@ -1019,13 +1022,14 @@ CURLcode HttpOperation::Setup() } #if LIBCURL_VERSION_NUM >= 0x072000 - rc = SetCurlPtrOption(CURLOPT_XFERINFOFUNCTION, (void *)&HttpOperation::OnProgressCallback); + rc = SetCurlPtrOption(CURLOPT_XFERINFOFUNCTION, + reinterpret_cast(&HttpOperation::OnProgressCallback)); if (rc != CURLE_OK) { return rc; } - rc = SetCurlPtrOption(CURLOPT_XFERINFODATA, (void *)this); + rc = SetCurlPtrOption(CURLOPT_XFERINFODATA, static_cast(this)); if (rc != CURLE_OK) { return rc; @@ -1037,7 +1041,7 @@ CURLcode HttpOperation::Setup() return rc; } - rc = SetCurlPtrOption(CURLOPT_PROGRESSDATA, (void *)this); + rc = SetCurlPtrOption(CURLOPT_PROGRESSDATA, static_cast(this)); if (rc != CURLE_OK) { return rc; @@ -1045,13 +1049,14 @@ CURLcode HttpOperation::Setup() #endif #if LIBCURL_VERSION_NUM >= 0x075000 - rc = SetCurlPtrOption(CURLOPT_PREREQFUNCTION, (void *)&HttpOperation::PreRequestCallback); + rc = SetCurlPtrOption(CURLOPT_PREREQFUNCTION, + reinterpret_cast(&HttpOperation::PreRequestCallback)); if (rc != CURLE_OK) { return rc; } - rc = SetCurlPtrOption(CURLOPT_PREREQDATA, (void *)this); + rc = SetCurlPtrOption(CURLOPT_PREREQDATA, static_cast(this)); if (rc != CURLE_OK) { return rc; @@ -1148,7 +1153,8 @@ Headers HttpOperation::GetResponseHeaders() return result; std::stringstream ss; - std::string headers((const char *)&response_headers_[0], response_headers_.size()); + std::string headers(reinterpret_cast(&response_headers_[0]), + response_headers_.size()); ss.str(headers); std::string header; diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h index 6f9bf803f0..f346160107 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h @@ -56,7 +56,7 @@ class HistogramExemplarReservoir : public FixedSizeExemplarReservoir const MetricAttributes &attributes, const opentelemetry::context::Context &context) override { - return ReservoirCellIndexFor(cells, (double)value, attributes, context); + return ReservoirCellIndexFor(cells, static_cast(value), attributes, context); } int ReservoirCellIndexFor(const std::vector & /* cells */, diff --git a/sdk/src/common/base64.cc b/sdk/src/common/base64.cc index 04a865ffe8..a19af1f8a3 100644 --- a/sdk/src/common/base64.cc +++ b/sdk/src/common/base64.cc @@ -261,21 +261,21 @@ static int Base64UnescapeInternal(unsigned char *dst, if (++n == 4) { n = 0; - *p++ = (unsigned char)(x >> 16); - *p++ = (unsigned char)(x >> 8); - *p++ = (unsigned char)(x); + *p++ = static_cast(x >> 16); + *p++ = static_cast(x >> 8); + *p++ = static_cast(x); } } // no padding, the tail code if (n == 2) { - *p++ = (unsigned char)(x >> 4); + *p++ = static_cast(x >> 4); } else if (n == 3) { - *p++ = (unsigned char)(x >> 10); - *p++ = (unsigned char)(x >> 2); + *p++ = static_cast(x >> 10); + *p++ = static_cast(x >> 2); } *olen = static_cast(p - dst); diff --git a/sdk/src/metrics/aggregation/histogram_aggregation.cc b/sdk/src/metrics/aggregation/histogram_aggregation.cc index 1aa02637ea..8e14ddec7a 100644 --- a/sdk/src/metrics/aggregation/histogram_aggregation.cc +++ b/sdk/src/metrics/aggregation/histogram_aggregation.cc @@ -35,7 +35,7 @@ LongHistogramAggregation::LongHistogramAggregation(const AggregationConfig *aggr record_min_max_ = ac->record_min_max_; } point_data_.counts_ = std::vector(point_data_.boundaries_.size() + 1, 0); - point_data_.sum_ = (int64_t)0; + point_data_.sum_ = static_cast(0); point_data_.count_ = 0; point_data_.record_min_max_ = record_min_max_; point_data_.min_ = (std::numeric_limits::max)(); diff --git a/sdk/src/metrics/aggregation/lastvalue_aggregation.cc b/sdk/src/metrics/aggregation/lastvalue_aggregation.cc index d6b89acde8..50904f8184 100644 --- a/sdk/src/metrics/aggregation/lastvalue_aggregation.cc +++ b/sdk/src/metrics/aggregation/lastvalue_aggregation.cc @@ -16,7 +16,7 @@ namespace metrics LongLastValueAggregation::LongLastValueAggregation() { point_data_.is_lastvalue_valid_ = false; - point_data_.value_ = (int64_t)0; + point_data_.value_ = static_cast(0); } LongLastValueAggregation::LongLastValueAggregation(LastValuePointData &&data) diff --git a/sdk/src/metrics/aggregation/sum_aggregation.cc b/sdk/src/metrics/aggregation/sum_aggregation.cc index f3c88ad13c..0901a7bbdd 100644 --- a/sdk/src/metrics/aggregation/sum_aggregation.cc +++ b/sdk/src/metrics/aggregation/sum_aggregation.cc @@ -17,7 +17,7 @@ namespace metrics LongSumAggregation::LongSumAggregation(bool is_monotonic) { - point_data_.value_ = (int64_t)0; + point_data_.value_ = static_cast(0); point_data_.is_monotonic_ = is_monotonic; } diff --git a/sdk/src/trace/samplers/trace_id_ratio.cc b/sdk/src/trace/samplers/trace_id_ratio.cc index f7bb67f150..4d5d3453fa 100644 --- a/sdk/src/trace/samplers/trace_id_ratio.cc +++ b/sdk/src/trace/samplers/trace_id_ratio.cc @@ -51,7 +51,7 @@ uint64_t CalculateThresholdFromBuffer(const trace_api::TraceId &trace_id) noexce uint64_t res = 0; std::memcpy(&res, &trace_id, 8); - double ratio = (double)res / (double)UINT64_MAX; + double ratio = static_cast(res) / static_cast(UINT64_MAX); return CalculateThreshold(ratio); } diff --git a/sdk/test/logs/log_record_test.cc b/sdk/test/logs/log_record_test.cc index 689ca7f8ed..bd9e462012 100644 --- a/sdk/test/logs/log_record_test.cc +++ b/sdk/test/logs/log_record_test.cc @@ -52,7 +52,7 @@ TEST(ReadWriteLogRecord, SetAndGet) record.SetSeverity(logs_api::Severity::kInvalid); record.SetBody("Message"); record.SetResource(resource); - record.SetAttribute("attr1", (int64_t)314159); + record.SetAttribute("attr1", static_cast(314159)); record.SetTraceId(trace_id); record.SetSpanId(span_id); record.SetTraceFlags(trace_flags); diff --git a/sdk/test/metrics/aggregation_test.cc b/sdk/test/metrics/aggregation_test.cc index 94e5f4c1fa..d52cc9e732 100644 --- a/sdk/test/metrics/aggregation_test.cc +++ b/sdk/test/metrics/aggregation_test.cc @@ -20,8 +20,8 @@ TEST(Aggregation, LongSumAggregation) auto sum_data = nostd::get(data); ASSERT_TRUE(nostd::holds_alternative(sum_data.value_)); EXPECT_EQ(nostd::get(sum_data.value_), 0); - aggr.Aggregate((int64_t)12, {}); - aggr.Aggregate((int64_t)0, {}); + aggr.Aggregate(static_cast(12), {}); + aggr.Aggregate(static_cast(0), {}); sum_data = nostd::get(aggr.ToPoint()); EXPECT_EQ(nostd::get(sum_data.value_), 12); } @@ -48,8 +48,8 @@ TEST(Aggregation, LongLastValueAggregation) auto lastvalue_data = nostd::get(data); ASSERT_TRUE(nostd::holds_alternative(lastvalue_data.value_)); EXPECT_EQ(lastvalue_data.is_lastvalue_valid_, false); - aggr.Aggregate((int64_t)12, {}); - aggr.Aggregate((int64_t)1, {}); + aggr.Aggregate(static_cast(12), {}); + aggr.Aggregate(static_cast(1), {}); lastvalue_data = nostd::get(aggr.ToPoint()); EXPECT_EQ(nostd::get(lastvalue_data.value_), 1.0); } @@ -77,8 +77,8 @@ TEST(Aggregation, LongHistogramAggregation) ASSERT_TRUE(nostd::holds_alternative(histogram_data.sum_)); EXPECT_EQ(nostd::get(histogram_data.sum_), 0); EXPECT_EQ(histogram_data.count_, 0); - aggr.Aggregate((int64_t)12, {}); // lies in third bucket - aggr.Aggregate((int64_t)100, {}); // lies in sixth bucket + aggr.Aggregate(static_cast(12), {}); // lies in third bucket + aggr.Aggregate(static_cast(100), {}); // lies in sixth bucket histogram_data = nostd::get(aggr.ToPoint()); EXPECT_EQ(nostd::get(histogram_data.min_), 12); EXPECT_EQ(nostd::get(histogram_data.max_), 100); @@ -86,8 +86,8 @@ TEST(Aggregation, LongHistogramAggregation) EXPECT_EQ(histogram_data.count_, 2); EXPECT_EQ(histogram_data.counts_[3], 1); EXPECT_EQ(histogram_data.counts_[6], 1); - aggr.Aggregate((int64_t)13, {}); // lies in third bucket - aggr.Aggregate((int64_t)252, {}); // lies in eight bucket + aggr.Aggregate(static_cast(13), {}); // lies in third bucket + aggr.Aggregate(static_cast(252), {}); // lies in eight bucket histogram_data = nostd::get(aggr.ToPoint()); EXPECT_EQ(histogram_data.count_, 4); EXPECT_EQ(histogram_data.counts_[3], 2); @@ -97,16 +97,16 @@ TEST(Aggregation, LongHistogramAggregation) // Merge LongHistogramAggregation aggr1; - aggr1.Aggregate((int64_t)1, {}); - aggr1.Aggregate((int64_t)11, {}); - aggr1.Aggregate((int64_t)26, {}); + aggr1.Aggregate(static_cast(1), {}); + aggr1.Aggregate(static_cast(11), {}); + aggr1.Aggregate(static_cast(26), {}); LongHistogramAggregation aggr2; - aggr2.Aggregate((int64_t)2, {}); - aggr2.Aggregate((int64_t)3, {}); - aggr2.Aggregate((int64_t)13, {}); - aggr2.Aggregate((int64_t)28, {}); - aggr2.Aggregate((int64_t)105, {}); + aggr2.Aggregate(static_cast(2), {}); + aggr2.Aggregate(static_cast(3), {}); + aggr2.Aggregate(static_cast(13), {}); + aggr2.Aggregate(static_cast(28), {}); + aggr2.Aggregate(static_cast(105), {}); auto aggr3 = aggr1.Merge(aggr2); histogram_data = nostd::get(aggr3->ToPoint()); diff --git a/sdk/test/metrics/attributes_hashmap_benchmark.cc b/sdk/test/metrics/attributes_hashmap_benchmark.cc index 0568080a6d..5dc02ca5be 100644 --- a/sdk/test/metrics/attributes_hashmap_benchmark.cc +++ b/sdk/test/metrics/attributes_hashmap_benchmark.cc @@ -36,7 +36,7 @@ void BM_AttributseHashMap(benchmark::State &state) m.lock(); auto hash = opentelemetry::sdk::common::GetHashForAttributeMap(attributes[i % 2]); hash_map.GetOrSetDefault(attributes[i % 2], create_default_aggregation, hash) - ->Aggregate((int64_t)1); + ->Aggregate(static_cast(1)); benchmark::DoNotOptimize(hash_map.Has(hash)); m.unlock(); }; diff --git a/sdk/test/metrics/attributes_hashmap_test.cc b/sdk/test/metrics/attributes_hashmap_test.cc index 956a76dfe1..7e03deed47 100644 --- a/sdk/test/metrics/attributes_hashmap_test.cc +++ b/sdk/test/metrics/attributes_hashmap_test.cc @@ -27,14 +27,14 @@ TEST(AttributesHashMap, BasicTests) std::unique_ptr aggregation1( new DropAggregation()); // = std::unique_ptr(new DropAggregation); hash_map.Set(m1, std::move(aggregation1), hash); - EXPECT_NO_THROW(hash_map.Get(hash)->Aggregate((int64_t)1)); + EXPECT_NO_THROW(hash_map.Get(hash)->Aggregate(static_cast(1))); EXPECT_EQ(hash_map.Size(), 1); EXPECT_EQ(hash_map.Has(hash), true); // Set same key again auto aggregation2 = std::unique_ptr(new DropAggregation()); hash_map.Set(m1, std::move(aggregation2), hash); - EXPECT_NO_THROW(hash_map.Get(hash)->Aggregate((int64_t)1)); + EXPECT_NO_THROW(hash_map.Get(hash)->Aggregate(static_cast(1))); EXPECT_EQ(hash_map.Size(), 1); EXPECT_EQ(hash_map.Has(hash), true); @@ -45,7 +45,7 @@ TEST(AttributesHashMap, BasicTests) hash_map.Set(m3, std::move(aggregation3), hash3); EXPECT_EQ(hash_map.Has(hash), true); EXPECT_EQ(hash_map.Has(hash3), true); - EXPECT_NO_THROW(hash_map.Get(hash3)->Aggregate((int64_t)1)); + EXPECT_NO_THROW(hash_map.Get(hash3)->Aggregate(static_cast(1))); EXPECT_EQ(hash_map.Size(), 2); // GetOrSetDefault @@ -55,8 +55,8 @@ TEST(AttributesHashMap, BasicTests) }; MetricAttributes m4 = {{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}; auto hash4 = opentelemetry::sdk::common::GetHashForAttributeMap(m4); - EXPECT_NO_THROW( - hash_map.GetOrSetDefault(m4, create_default_aggregation, hash4)->Aggregate((int64_t)1)); + EXPECT_NO_THROW(hash_map.GetOrSetDefault(m4, create_default_aggregation, hash4) + ->Aggregate(static_cast(1))); EXPECT_EQ(hash_map.Size(), 3); // Set attributes with different order - shouldn't create a new entry. diff --git a/sdk/test/metrics/exemplar/always_sample_filter_test.cc b/sdk/test/metrics/exemplar/always_sample_filter_test.cc index 30c86fd37f..f78cd412bd 100644 --- a/sdk/test/metrics/exemplar/always_sample_filter_test.cc +++ b/sdk/test/metrics/exemplar/always_sample_filter_test.cc @@ -13,6 +13,6 @@ TEST(AlwaysSampleFilter, SampleMeasurement) auto filter = opentelemetry::sdk::metrics::ExemplarFilter::GetAlwaysSampleFilter(); ASSERT_TRUE( filter->ShouldSampleMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{})); - ASSERT_TRUE(filter->ShouldSampleMeasurement((int64_t)1, MetricAttributes{}, + ASSERT_TRUE(filter->ShouldSampleMeasurement(static_cast(1), MetricAttributes{}, opentelemetry::context::Context{})); } diff --git a/sdk/test/metrics/exemplar/histogram_exemplar_reservoir_test.cc b/sdk/test/metrics/exemplar/histogram_exemplar_reservoir_test.cc index a26b0eb952..927d6bdd31 100644 --- a/sdk/test/metrics/exemplar/histogram_exemplar_reservoir_test.cc +++ b/sdk/test/metrics/exemplar/histogram_exemplar_reservoir_test.cc @@ -22,7 +22,7 @@ TEST_F(HistogramExemplarReservoirTestPeer, OfferMeasurement) boundaries.size(), HistogramExemplarReservoir::GetHistogramCellSelector(boundaries), nullptr); histogram_exemplar_reservoir->OfferMeasurement( 1.0, MetricAttributes{}, opentelemetry::context::Context{}, std::chrono::system_clock::now()); - histogram_exemplar_reservoir->OfferMeasurement((int64_t)1, MetricAttributes{}, + histogram_exemplar_reservoir->OfferMeasurement(static_cast(1), MetricAttributes{}, opentelemetry::context::Context{}, std::chrono::system_clock::now()); auto exemplar_data = histogram_exemplar_reservoir->CollectAndReset(MetricAttributes{}); diff --git a/sdk/test/metrics/exemplar/never_sample_filter_test.cc b/sdk/test/metrics/exemplar/never_sample_filter_test.cc index 4428f60104..e00d9f2962 100644 --- a/sdk/test/metrics/exemplar/never_sample_filter_test.cc +++ b/sdk/test/metrics/exemplar/never_sample_filter_test.cc @@ -12,6 +12,6 @@ TEST(NeverSampleFilter, SampleMeasurement) auto filter = opentelemetry::sdk::metrics::ExemplarFilter::GetNeverSampleFilter(); ASSERT_FALSE( filter->ShouldSampleMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{})); - ASSERT_FALSE(filter->ShouldSampleMeasurement((int64_t)1, MetricAttributes{}, + ASSERT_FALSE(filter->ShouldSampleMeasurement(static_cast(1), MetricAttributes{}, opentelemetry::context::Context{})); } diff --git a/sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc b/sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc index ebf79d2136..ac86350af4 100644 --- a/sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc +++ b/sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc @@ -11,8 +11,8 @@ TEST(NoExemplarReservoir, OfferMeasurement) auto reservoir = opentelemetry::sdk::metrics::ExemplarReservoir::GetNoExemplarReservoir(); reservoir->OfferMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{}, std::chrono::system_clock::now()); - reservoir->OfferMeasurement((int64_t)1, MetricAttributes{}, opentelemetry::context::Context{}, - std::chrono::system_clock::now()); + reservoir->OfferMeasurement(static_cast(1), MetricAttributes{}, + opentelemetry::context::Context{}, std::chrono::system_clock::now()); auto exemplar_data = reservoir->CollectAndReset(MetricAttributes{}); ASSERT_TRUE(exemplar_data.empty()); } diff --git a/sdk/test/metrics/exemplar/reservoir_cell_test.cc b/sdk/test/metrics/exemplar/reservoir_cell_test.cc index 0285279728..7522a36312 100644 --- a/sdk/test/metrics/exemplar/reservoir_cell_test.cc +++ b/sdk/test/metrics/exemplar/reservoir_cell_test.cc @@ -41,7 +41,7 @@ class ReservoirCellTestPeer : public ::testing::Test TEST_F(ReservoirCellTestPeer, recordMeasurement) { opentelemetry::sdk::metrics::ReservoirCell reservoir_cell; - reservoir_cell.RecordLongMeasurement((int64_t)1, MetricAttributes{}, + reservoir_cell.RecordLongMeasurement(static_cast(1), MetricAttributes{}, opentelemetry::context::Context{}); ASSERT_TRUE(GetLongVal(reservoir_cell) == 1); diff --git a/sdk/test/metrics/exemplar/with_trace_sample_filter_test.cc b/sdk/test/metrics/exemplar/with_trace_sample_filter_test.cc index be22f93f06..fcf9d6344e 100644 --- a/sdk/test/metrics/exemplar/with_trace_sample_filter_test.cc +++ b/sdk/test/metrics/exemplar/with_trace_sample_filter_test.cc @@ -12,6 +12,6 @@ TEST(WithTraceSampleFilter, SampleMeasurement) auto filter = opentelemetry::sdk::metrics::ExemplarFilter::GetWithTraceSampleFilter(); ASSERT_FALSE( filter->ShouldSampleMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{})); - ASSERT_FALSE(filter->ShouldSampleMeasurement((int64_t)1, MetricAttributes{}, + ASSERT_FALSE(filter->ShouldSampleMeasurement(static_cast(1), MetricAttributes{}, opentelemetry::context::Context{})); } diff --git a/sdk/test/metrics/histogram_aggregation_benchmark.cc b/sdk/test/metrics/histogram_aggregation_benchmark.cc index bb63f1230c..f85a4f4706 100644 --- a/sdk/test/metrics/histogram_aggregation_benchmark.cc +++ b/sdk/test/metrics/histogram_aggregation_benchmark.cc @@ -35,7 +35,7 @@ void BM_HistogramAggregation(benchmark::State &state) double measurements[TOTAL_MEASUREMENTS]; for (size_t i = 0; i < TOTAL_MEASUREMENTS; i++) { - measurements[i] = (double)distribution(generator); + measurements[i] = static_cast(distribution(generator)); } std::vector actuals; std::vector collectionThreads; diff --git a/sdk/test/metrics/sum_aggregation_benchmark.cc b/sdk/test/metrics/sum_aggregation_benchmark.cc index 43be12523a..728b3542a1 100644 --- a/sdk/test/metrics/sum_aggregation_benchmark.cc +++ b/sdk/test/metrics/sum_aggregation_benchmark.cc @@ -36,7 +36,7 @@ void BM_SumAggregation(benchmark::State &state) double measurements[TOTAL_MEASUREMENTS]; for (size_t i = 0; i < TOTAL_MEASUREMENTS; i++) { - measurements[i] = (double)distribution(generator); + measurements[i] = static_cast(distribution(generator)); } std::vector actuals; std::vector collectionThreads; diff --git a/sdk/test/resource/resource_test.cc b/sdk/test/resource/resource_test.cc index 96de75c04a..828a9ac355 100644 --- a/sdk/test/resource/resource_test.cc +++ b/sdk/test/resource/resource_test.cc @@ -34,7 +34,7 @@ TEST(ResourceTest, create_without_servicename) { ResourceAttributes expected_attributes = { {"service", "backend"}, - {"version", (uint32_t)1}, + {"version", static_cast(1)}, {"cost", 234.23}, {SemanticConventions::kTelemetrySdkLanguage, "cpp"}, {SemanticConventions::kTelemetrySdkName, "opentelemetry"}, @@ -42,7 +42,7 @@ TEST(ResourceTest, create_without_servicename) {SemanticConventions::kServiceName, "unknown_service"}}; ResourceAttributes attributes = { - {"service", "backend"}, {"version", (uint32_t)1}, {"cost", 234.23}}; + {"service", "backend"}, {"version", static_cast(1)}, {"cost", 234.23}}; auto resource = Resource::Create(attributes); auto received_attributes = resource.GetAttributes(); for (auto &e : received_attributes) @@ -67,7 +67,7 @@ TEST(ResourceTest, create_without_servicename) TEST(ResourceTest, create_with_servicename) { ResourceAttributes expected_attributes = { - {"version", (uint32_t)1}, + {"version", static_cast(1)}, {"cost", 234.23}, {SemanticConventions::kTelemetrySdkLanguage, "cpp"}, {SemanticConventions::kTelemetrySdkName, "opentelemetry"}, @@ -75,7 +75,7 @@ TEST(ResourceTest, create_with_servicename) {SemanticConventions::kServiceName, "backend"}, }; ResourceAttributes attributes = { - {"service.name", "backend"}, {"version", (uint32_t)1}, {"cost", 234.23}}; + {"service.name", "backend"}, {"version", static_cast(1)}, {"cost", 234.23}}; auto resource = Resource::Create(attributes); auto received_attributes = resource.GetAttributes(); for (auto &e : received_attributes) diff --git a/sdk/test/trace/span_data_test.cc b/sdk/test/trace/span_data_test.cc index 7a6c66c91e..98d00843dd 100644 --- a/sdk/test/trace/span_data_test.cc +++ b/sdk/test/trace/span_data_test.cc @@ -54,7 +54,7 @@ TEST(SpanData, Set) data.SetStatus(trace_api::StatusCode::kOk, "description"); data.SetStartTime(now); data.SetDuration(std::chrono::nanoseconds(1000000)); - data.SetAttribute("attr1", (int64_t)314159); + data.SetAttribute("attr1", static_cast(314159)); data.AddEvent("event1", now); ASSERT_EQ(data.GetTraceId(), trace_id); diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 78bdbc9a43..a84a0125c1 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -237,11 +237,11 @@ TEST(Tracer, StartSpanWithAttributes) ->StartSpan("span 1", {{"attr1", "string"}, {"attr2", false}, {"attr1", 314159}, - {"attr3", (unsigned int)314159}, - {"attr4", (int32_t)-20}, - {"attr5", (uint32_t)20}, - {"attr6", (int64_t)-20}, - {"attr7", (uint64_t)20}, + {"attr3", static_cast(314159)}, + {"attr4", static_cast(-20)}, + {"attr5", static_cast(20)}, + {"attr6", static_cast(-20)}, + {"attr7", static_cast(20)}, {"attr8", 3.1}, {"attr9", "string"}}) ->End(); @@ -276,11 +276,14 @@ TEST(Tracer, StartSpanWithAttributes) ASSERT_EQ(9, cur_span_data->GetAttributes().size()); ASSERT_EQ(314159, nostd::get(cur_span_data->GetAttributes().at("attr1"))); ASSERT_EQ(false, nostd::get(cur_span_data->GetAttributes().at("attr2"))); - ASSERT_EQ((uint32_t)314159, nostd::get(cur_span_data->GetAttributes().at("attr3"))); + ASSERT_EQ(static_cast(314159), + nostd::get(cur_span_data->GetAttributes().at("attr3"))); ASSERT_EQ(-20, nostd::get(cur_span_data->GetAttributes().at("attr4"))); - ASSERT_EQ((uint32_t)20, nostd::get(cur_span_data->GetAttributes().at("attr5"))); + ASSERT_EQ(static_cast(20), + nostd::get(cur_span_data->GetAttributes().at("attr5"))); ASSERT_EQ(-20, nostd::get(cur_span_data->GetAttributes().at("attr6"))); - ASSERT_EQ((uint64_t)20, nostd::get(cur_span_data->GetAttributes().at("attr7"))); + ASSERT_EQ(static_cast(20), + nostd::get(cur_span_data->GetAttributes().at("attr7"))); ASSERT_EQ(3.1, nostd::get(cur_span_data->GetAttributes().at("attr8"))); ASSERT_EQ("string", nostd::get(cur_span_data->GetAttributes().at("attr9")));