Skip to content

Commit

Permalink
Remove the implementation of absl::variant, which was only needed
Browse files Browse the repository at this point in the history
prior to C++17. `absl::variant` is now an alias for `std::variant`.
It is recommended that clients simply use `std::variant`.

PiperOrigin-RevId: 730940936
Change-Id: I7157612a62eec036abf61dd1ad42c5945afeac1d
  • Loading branch information
derekmauro authored and copybara-github committed Feb 25, 2025
1 parent ea9951d commit aea2fc0
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 6,125 deletions.
4 changes: 0 additions & 4 deletions CMake/AbseilDll.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,7 @@ set(ABSL_INTERNAL_DLL_FILES
"time/internal/cctz/src/tzfile.h"
"time/internal/cctz/src/zone_info_source.cc"
"types/any.h"
"types/bad_variant_access.cc"
"types/bad_variant_access.h"
"types/compare.h"
"types/internal/variant.h"
"types/optional.h"
"types/span.h"
"types/internal/span.h"
Expand Down Expand Up @@ -488,7 +485,6 @@ set(ABSL_INTERNAL_DLL_TARGETS
"any"
"any_invocable"
"atomic_hook"
"bad_variant_access"
"base"
"base_internal"
"bind_front"
Expand Down
36 changes: 1 addition & 35 deletions absl/base/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,19 +522,8 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#define ABSL_USES_STD_ANY 1
#define ABSL_HAVE_STD_OPTIONAL 1
#define ABSL_USES_STD_OPTIONAL 1

// ABSL_HAVE_STD_VARIANT
//
// Checks whether C++17 std::variant is available.
#ifdef ABSL_HAVE_STD_VARIANT
#error "ABSL_HAVE_STD_VARIANT cannot be directly set."
#elif defined(__cpp_lib_variant) && __cpp_lib_variant >= 201606L
#define ABSL_HAVE_STD_VARIANT 1
#elif defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \
ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L && \
!ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
#define ABSL_HAVE_STD_VARIANT 1
#endif
#define ABSL_USES_STD_VARIANT 1

// ABSL_HAVE_STD_STRING_VIEW
//
Expand Down Expand Up @@ -564,21 +553,6 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#define ABSL_HAVE_STD_ORDERING 1
#endif

// ABSL_USES_STD_VARIANT
//
// Indicates whether absl::variant is an alias for std::variant.
#if !defined(ABSL_OPTION_USE_STD_VARIANT)
#error options.h is misconfigured.
#elif ABSL_OPTION_USE_STD_VARIANT == 0 || \
(ABSL_OPTION_USE_STD_VARIANT == 2 && !defined(ABSL_HAVE_STD_VARIANT))
#undef ABSL_USES_STD_VARIANT
#elif ABSL_OPTION_USE_STD_VARIANT == 1 || \
(ABSL_OPTION_USE_STD_VARIANT == 2 && defined(ABSL_HAVE_STD_VARIANT))
#define ABSL_USES_STD_VARIANT 1
#else
#error options.h is misconfigured.
#endif

// ABSL_USES_STD_STRING_VIEW
//
// Indicates whether absl::string_view is an alias for std::string_view.
Expand Down Expand Up @@ -612,14 +586,6 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#error options.h is misconfigured.
#endif

// In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
// SEH exception from emplace for variant<SomeStruct> when constructing the
// struct can throw. This defeats some of variant_test and
// variant_exception_safety_test.
#if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG)
#define ABSL_INTERNAL_MSVC_2017_DBG_MODE
#endif

// ABSL_INTERNAL_MANGLED_NS
// ABSL_INTERNAL_MANGLED_BACKREFERENCE
//
Expand Down
26 changes: 0 additions & 26 deletions absl/base/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,6 @@

#define ABSL_OPTION_USE_STD_STRING_VIEW 2

// ABSL_OPTION_USE_STD_VARIANT
//
// This option controls whether absl::variant is implemented as an alias to
// std::variant, or as an independent implementation.
//
// A value of 0 means to use Abseil's implementation. This requires only C++11
// support, and is expected to work on every toolchain we support.
//
// A value of 1 means to use an alias to std::variant. This requires that all
// code using Abseil is built in C++17 mode or later.
//
// A value of 2 means to detect the C++ version being used to compile Abseil,
// and use an alias only if a working std::variant is available. This option
// is useful when you are building your program from source. It should not be
// used otherwise -- for example, if you are distributing Abseil in a binary
// package manager -- since in mode 2, absl::variant will name a different
// type, with a different mangled name and binary layout, depending on the
// compiler flags passed by the end user. For more info, see
// https://abseil.io/about/design/dropin-types.
//
// User code should not inspect this macro. To check in the preprocessor if
// absl::variant is a typedef of std::variant, use the feature macro
// ABSL_USES_STD_VARIANT.

#define ABSL_OPTION_USE_STD_VARIANT 2

// ABSL_OPTION_USE_STD_ORDERING
//
// This option controls whether absl::{partial,weak,strong}_ordering are
Expand Down
61 changes: 5 additions & 56 deletions absl/types/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -105,81 +105,30 @@ cc_library(
deprecation = "bad_optional_access dependency is empty can be removed",
)

cc_library(
name = "bad_variant_access",
srcs = ["bad_variant_access.cc"],
hdrs = ["bad_variant_access.h"],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
"//absl/base:config",
"//absl/base:raw_logging_internal",
],
)

cc_library(
name = "variant",
srcs = ["internal/variant.h"],
hdrs = ["variant.h"],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":bad_variant_access",
"//absl/base:base_internal",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/meta:type_traits",
"//absl/utility",
],
)

cc_test(
name = "variant_test",
size = "small",
srcs = ["variant_test.cc"],
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":variant",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/memory",
"//absl/meta:type_traits",
"//absl/strings",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)

cc_test(
name = "variant_benchmark",
srcs = [
"variant_benchmark.cc",
],
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
tags = ["benchmark"],
deps = [
":variant",
"//absl/utility",
"@google_benchmark//:benchmark_main",
"@googletest//:gtest",
],
cc_library(
name = "bad_variant_access",
deprecation = "bad_variant_access dependency is empty can be removed",
)

cc_test(
name = "variant_exception_safety_test",
name = "variant_test",
size = "small",
srcs = [
"variant_exception_safety_test.cc",
],
srcs = ["variant_test.cc"],
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":variant",
"//absl/base:config",
"//absl/base:exception_safety_testing",
"//absl/memory",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
Expand Down
41 changes: 0 additions & 41 deletions absl/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,36 +100,15 @@ absl_cc_library(
PUBLIC
)

absl_cc_library(
NAME
bad_variant_access
HDRS
"bad_variant_access.h"
SRCS
"bad_variant_access.cc"
COPTS
${ABSL_DEFAULT_COPTS}
DEPS
absl::config
absl::raw_logging_internal
PUBLIC
)

absl_cc_library(
NAME
variant
HDRS
"variant.h"
SRCS
"internal/variant.h"
COPTS
${ABSL_DEFAULT_COPTS}
DEPS
absl::bad_variant_access
absl::base_internal
absl::config
absl::core_headers
absl::type_traits
absl::utility
PUBLIC
)
Expand All @@ -143,11 +122,6 @@ absl_cc_test(
${ABSL_TEST_COPTS}
DEPS
absl::variant
absl::config
absl::core_headers
absl::memory
absl::type_traits
absl::strings
GTest::gmock_main
)

Expand Down Expand Up @@ -177,18 +151,3 @@ absl_cc_test(
absl::compare
GTest::gmock_main
)

absl_cc_test(
NAME
variant_exception_safety_test
SRCS
"variant_exception_safety_test.cc"
COPTS
${ABSL_TEST_COPTS}
DEPS
absl::variant
absl::config
absl::exception_safety_testing
absl::memory
GTest::gmock_main
)
82 changes: 0 additions & 82 deletions absl/types/bad_variant_access.cc

This file was deleted.

Loading

0 comments on commit aea2fc0

Please sign in to comment.