From 9e63f94afc761e4f3a92b2d98a5d146835e4c346 Mon Sep 17 00:00:00 2001 From: Max Golovanov Date: Tue, 8 Jun 2021 12:57:12 -0700 Subject: [PATCH 1/6] Fixes for Visual Studio 2015 --- CMakeLists.txt | 2 +- api/include/opentelemetry/trace/propagation/b3_propagator.h | 4 ++-- api/test/nostd/variant_test.cc | 2 ++ .../opentelemetry/exporters/etw/etw_traceloggingdynamic.h | 5 +++-- exporters/etw/test/etw_perf_test.cc | 4 +--- exporters/etw/test/etw_tracer_test.cc | 4 +--- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8bce5be1f..5fb65bdedc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,7 @@ if(WITH_STL) add_definitions(-DHAVE_CPP_STDLIB) add_definitions(-DHAVE_GSL) # Require at least C++17. C++20 is needed to avoid gsl::span - if(CMAKE_MINOR_VERSION VERSION_GREATER "3.18") + if(CMAKE_VERSION VERSION_GREATER 3.18.0) # Ask for 20, may get anything below set(CMAKE_CXX_STANDARD 20) else() diff --git a/api/include/opentelemetry/trace/propagation/b3_propagator.h b/api/include/opentelemetry/trace/propagation/b3_propagator.h index 77d736bedc..88a811a5da 100644 --- a/api/include/opentelemetry/trace/propagation/b3_propagator.h +++ b/api/include/opentelemetry/trace/propagation/b3_propagator.h @@ -140,10 +140,10 @@ class B3Propagator : public B3PropagatorExtractor char trace_identity[kTraceIdHexStrLength + kSpanIdHexStrLength + 3]; static_assert(sizeof(trace_identity) == 51, "b3 trace identity buffer size mismatch"); span_context.trace_id().ToLowerBase16( - nostd::span{&trace_identity[0], kTraceIdHexStrLength}); + nostd::span{&trace_identity[0], static_cast(kTraceIdHexStrLength)}); trace_identity[kTraceIdHexStrLength] = '-'; span_context.span_id().ToLowerBase16(nostd::span{ - &trace_identity[kTraceIdHexStrLength + 1], kSpanIdHexStrLength}); + &trace_identity[kTraceIdHexStrLength + 1], static_cast(kSpanIdHexStrLength)}); trace_identity[kTraceIdHexStrLength + kSpanIdHexStrLength + 1] = '-'; trace_identity[kTraceIdHexStrLength + kSpanIdHexStrLength + 2] = span_context.trace_flags().IsSampled() ? '1' : '0'; diff --git a/api/test/nostd/variant_test.cc b/api/test/nostd/variant_test.cc index 428d31e624..caaea1f8a6 100644 --- a/api/test/nostd/variant_test.cc +++ b/api/test/nostd/variant_test.cc @@ -27,6 +27,7 @@ TEST(VariantSizeTest, GetVariantSize) EXPECT_EQ((nostd::variant_size>::value), 2); } +#if 0 // Disable this test for now. It does not compile with Visual Studio 2015. TEST(VariantAlternativeTest, GetVariantSize) { EXPECT_TRUE((std::is_same>, int>::value)); @@ -35,6 +36,7 @@ TEST(VariantAlternativeTest, GetVariantSize) EXPECT_TRUE((std::is_same>, const double>::value)); } +#endif TEST(VariantTest, Get) { diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_traceloggingdynamic.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_traceloggingdynamic.h index 9fe479b7eb..a6243c46db 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_traceloggingdynamic.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_traceloggingdynamic.h @@ -8,7 +8,8 @@ # endif # endif #else -# ifdef HAVE_TLD -# include "TraceLoggingDynamic.h" +# ifndef HAVE_TLD +# define HAVE_TLD # endif +# include "TraceLoggingDynamic.h" #endif diff --git a/exporters/etw/test/etw_perf_test.cc b/exporters/etw/test/etw_perf_test.cc index f2d28c094b..d25ea73957 100644 --- a/exporters/etw/test/etw_perf_test.cc +++ b/exporters/etw/test/etw_perf_test.cc @@ -14,9 +14,7 @@ using namespace OPENTELEMETRY_NAMESPACE; -using Properties = opentelemetry::exporter::etw::Properties; -using PropertyValue = opentelemetry::exporter::etw::PropertyValue; -using PropertyValueMap = opentelemetry::exporter::etw::PropertyValueMap; +using namespace opentelemetry::exporter::etw; namespace { diff --git a/exporters/etw/test/etw_tracer_test.cc b/exporters/etw/test/etw_tracer_test.cc index 5d741d5b75..45d49356c8 100644 --- a/exporters/etw/test/etw_tracer_test.cc +++ b/exporters/etw/test/etw_tracer_test.cc @@ -12,9 +12,7 @@ using namespace OPENTELEMETRY_NAMESPACE; -using Properties = opentelemetry::exporter::etw::Properties; -using PropertyValue = opentelemetry::exporter::etw::PropertyValue; -using PropertyValueMap = opentelemetry::exporter::etw::PropertyValueMap; +using namespace opentelemetry::exporter::etw; std::string getTemporaryValue() { From 613ac358e172ebe26f6dab56673137c6269a230c Mon Sep 17 00:00:00 2001 From: Max Golovanov Date: Tue, 8 Jun 2021 13:49:06 -0700 Subject: [PATCH 2/6] Fix vc140 __cplusplus warning --- CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fb65bdedc..ab3b717a83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,8 +92,7 @@ if(WITH_STL) set(MSVC_CXX_OPT_FLAG "/O2") endif() endif() - set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} /Zc:__cplusplus ${MSVC_CXX_OPT_FLAG}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_CXX_OPT_FLAG}") endif() endif() @@ -168,8 +167,10 @@ if(MSVC) # Options for Visual C++ compiler: /Zc:__cplusplus - report an updated value # for recent C++ language standards. Without this option MSVC returns the # value of __cplusplus="199711L" - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus") - + if(MSVC_VERSION GREATER 1900) + # __cplusplus flag is not supported by Visual Studio 2015 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus") + endif() # When using vcpkg, all targets build with the same runtime if(VCPKG_TOOLCHAIN) set(CMAKE_MSVC_RUNTIME_LIBRARY From 4a3a1ffa32125627a9627cdeda6c9018f23712d7 Mon Sep 17 00:00:00 2001 From: Max Golovanov Date: Tue, 8 Jun 2021 13:49:25 -0700 Subject: [PATCH 3/6] Fix narrowing cast warning in vc140 --- api/include/opentelemetry/trace/propagation/b3_propagator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/include/opentelemetry/trace/propagation/b3_propagator.h b/api/include/opentelemetry/trace/propagation/b3_propagator.h index 88a811a5da..9aac90f03e 100644 --- a/api/include/opentelemetry/trace/propagation/b3_propagator.h +++ b/api/include/opentelemetry/trace/propagation/b3_propagator.h @@ -139,8 +139,8 @@ class B3Propagator : public B3PropagatorExtractor char trace_identity[kTraceIdHexStrLength + kSpanIdHexStrLength + 3]; static_assert(sizeof(trace_identity) == 51, "b3 trace identity buffer size mismatch"); - span_context.trace_id().ToLowerBase16( - nostd::span{&trace_identity[0], static_cast(kTraceIdHexStrLength)}); + span_context.trace_id().ToLowerBase16(nostd::span{ + &trace_identity[0], static_cast(kTraceIdHexStrLength)}); trace_identity[kTraceIdHexStrLength] = '-'; span_context.span_id().ToLowerBase16(nostd::span{ &trace_identity[kTraceIdHexStrLength + 1], static_cast(kSpanIdHexStrLength)}); From dc0c8e8f3a2fad0a5f6bf499eceb446aeb6d7574 Mon Sep 17 00:00:00 2001 From: Max Golovanov Date: Tue, 8 Jun 2021 13:49:59 -0700 Subject: [PATCH 4/6] Reorder headers in gRPC example to avoid conflict between absl:: classes. This issue is unique to vc140 and does not affect newer compilers. --- examples/grpc/client.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/grpc/client.cpp b/examples/grpc/client.cpp index 5ebdbf617d..719a62225b 100644 --- a/examples/grpc/client.cpp +++ b/examples/grpc/client.cpp @@ -1,12 +1,14 @@ +// Make sure to include GRPC headers first because otherwise Abseil may create +// ambiguity with `nostd::variant` if compiled with Visual Studio 2015. Other +// modern compilers are unaffected. +#include +#include "messages.grpc.pb.h" + #include "tracer_common.h" #include #include #include -#include - -#include "messages.grpc.pb.h" - using grpc::Channel; using grpc::ClientContext; using grpc::ClientReader; From ffe504a9dd8805786c8574909b52e054014da38a Mon Sep 17 00:00:00 2001 From: Max Golovanov Date: Tue, 8 Jun 2021 13:50:20 -0700 Subject: [PATCH 5/6] Fix std::copy compliance warning --- .../etw/include/opentelemetry/exporters/etw/etw_tracer.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h index 7cf6edea24..2806bfa593 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h @@ -291,8 +291,12 @@ static inline bool CopySpanIdToActivityId(const trace::SpanContext &spanContext, { return false; } - auto spanId = spanContext.span_id().Id().data(); - std::copy(spanId, spanId + 8, reinterpret_cast(&outGuid)); + auto spanId = spanContext.span_id().Id().data(); + uint8_t *guidPtr = reinterpret_cast(&outGuid); + for (size_t i = 0; i < 8; i++) + { + guidPtr[i] = spanId[i]; + } return true; }; From 2bfb5325a3c9b39dc5f0fc66a42ba663882a8f9f Mon Sep 17 00:00:00 2001 From: Max Golovanov Date: Tue, 8 Jun 2021 13:54:27 -0700 Subject: [PATCH 6/6] Fix code formatting error --- api/test/nostd/variant_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/test/nostd/variant_test.cc b/api/test/nostd/variant_test.cc index caaea1f8a6..cea5c4ee7b 100644 --- a/api/test/nostd/variant_test.cc +++ b/api/test/nostd/variant_test.cc @@ -27,7 +27,7 @@ TEST(VariantSizeTest, GetVariantSize) EXPECT_EQ((nostd::variant_size>::value), 2); } -#if 0 // Disable this test for now. It does not compile with Visual Studio 2015. +#if 0 // Disable this test for now. It does not compile with Visual Studio 2015. TEST(VariantAlternativeTest, GetVariantSize) { EXPECT_TRUE((std::is_same>, int>::value));