From 3e8c557eebc955d922afd7df96eb113b256e2853 Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Thu, 18 Jan 2024 09:31:51 -0800 Subject: [PATCH] Tweak some #if's to to be more correct under MSVC. --- .../nostd/internal/absl/base/policy_checks.h | 12 +++++++----- .../nostd/internal/absl/meta/type_traits.h | 3 ++- .../opentelemetry/exporters/ostream/common_utils.h | 9 ++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h b/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h index 02bdda4b63..f86c264fc4 100644 --- a/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h +++ b/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h @@ -71,13 +71,15 @@ // C++ Version Check // ----------------------------------------------------------------------------- -// Enforce C++11 as the minimum. Note that Visual Studio has not -// advanced __cplusplus despite being good enough for our purposes, so -// so we exempt it from the check. -#if defined(__cplusplus) && !defined(_MSC_VER) +// Enforce C++11 as the minimum. +#if defined(_MSVC_LANG) +#if _MSVC_LANG < 201103L +#error "C++ versions less than C++11 are not supported." +#endif // _MSVC_LANG < 201103L +#elif defined(__cplusplus) #if __cplusplus < 201103L #error "C++ versions less than C++11 are not supported." -#endif +#endif // __cplusplus < 201103L #endif // ----------------------------------------------------------------------------- diff --git a/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h b/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h index 489f6d47f9..8430f0087c 100644 --- a/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h +++ b/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h @@ -618,7 +618,8 @@ using underlying_type_t = typename std::underlying_type::type; namespace type_traits_internal { -#if __cplusplus >= 201703L +#if (!defined(_MSVC_LANG) && (__cplusplus >= 201703L)) || \ + (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)) // std::result_of is deprecated (C++17) or removed (C++20) template struct result_of; template diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h b/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h index 11e098c5c0..ec1ee2d367 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h @@ -58,7 +58,8 @@ void print_value(const nostd::span &vec, std::ostream &sout) } // Prior to C++14, generic lambda is not available so fallback to functor. -#if __cplusplus < 201402L +#if (!defined(_MSVC_LANG) && (__cplusplus < 201402L)) || \ + (defined(_MSVC_LANG) && (_MSVC_LANG < 201402L)) class OwnedAttributeValueVisitor { @@ -97,7 +98,8 @@ class AttributeValueVisitor inline void print_value(const opentelemetry::sdk::common::OwnedAttributeValue &value, std::ostream &sout) { -#if __cplusplus < 201402L +#if (!defined(_MSVC_LANG) && (__cplusplus < 201402L)) || \ + (defined(_MSVC_LANG) && (_MSVC_LANG < 201402L)) opentelemetry::nostd::visit(OwnedAttributeValueVisitor(sout), value); #else opentelemetry::nostd::visit( @@ -111,7 +113,8 @@ inline void print_value(const opentelemetry::sdk::common::OwnedAttributeValue &v inline void print_value(const opentelemetry::common::AttributeValue &value, std::ostream &sout) { -#if __cplusplus < 201402L +#if (!defined(_MSVC_LANG) && (__cplusplus < 201402L)) || \ + (defined(_MSVC_LANG) && (_MSVC_LANG < 201402L)) opentelemetry::nostd::visit(AttributeValueVisitor(sout), value); #else opentelemetry::nostd::visit(