Skip to content

Commit aea2fc0

Browse files
derekmaurocopybara-github
authored andcommitted
Remove the implementation of absl::variant, which was only needed
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
1 parent ea9951d commit aea2fc0

File tree

13 files changed

+58
-6125
lines changed

13 files changed

+58
-6125
lines changed

CMake/AbseilDll.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,7 @@ set(ABSL_INTERNAL_DLL_FILES
430430
"time/internal/cctz/src/tzfile.h"
431431
"time/internal/cctz/src/zone_info_source.cc"
432432
"types/any.h"
433-
"types/bad_variant_access.cc"
434-
"types/bad_variant_access.h"
435433
"types/compare.h"
436-
"types/internal/variant.h"
437434
"types/optional.h"
438435
"types/span.h"
439436
"types/internal/span.h"
@@ -488,7 +485,6 @@ set(ABSL_INTERNAL_DLL_TARGETS
488485
"any"
489486
"any_invocable"
490487
"atomic_hook"
491-
"bad_variant_access"
492488
"base"
493489
"base_internal"
494490
"bind_front"

absl/base/config.h

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -522,19 +522,8 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
522522
#define ABSL_USES_STD_ANY 1
523523
#define ABSL_HAVE_STD_OPTIONAL 1
524524
#define ABSL_USES_STD_OPTIONAL 1
525-
526-
// ABSL_HAVE_STD_VARIANT
527-
//
528-
// Checks whether C++17 std::variant is available.
529-
#ifdef ABSL_HAVE_STD_VARIANT
530-
#error "ABSL_HAVE_STD_VARIANT cannot be directly set."
531-
#elif defined(__cpp_lib_variant) && __cpp_lib_variant >= 201606L
532-
#define ABSL_HAVE_STD_VARIANT 1
533-
#elif defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \
534-
ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L && \
535-
!ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
536525
#define ABSL_HAVE_STD_VARIANT 1
537-
#endif
526+
#define ABSL_USES_STD_VARIANT 1
538527

539528
// ABSL_HAVE_STD_STRING_VIEW
540529
//
@@ -564,21 +553,6 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
564553
#define ABSL_HAVE_STD_ORDERING 1
565554
#endif
566555

567-
// ABSL_USES_STD_VARIANT
568-
//
569-
// Indicates whether absl::variant is an alias for std::variant.
570-
#if !defined(ABSL_OPTION_USE_STD_VARIANT)
571-
#error options.h is misconfigured.
572-
#elif ABSL_OPTION_USE_STD_VARIANT == 0 || \
573-
(ABSL_OPTION_USE_STD_VARIANT == 2 && !defined(ABSL_HAVE_STD_VARIANT))
574-
#undef ABSL_USES_STD_VARIANT
575-
#elif ABSL_OPTION_USE_STD_VARIANT == 1 || \
576-
(ABSL_OPTION_USE_STD_VARIANT == 2 && defined(ABSL_HAVE_STD_VARIANT))
577-
#define ABSL_USES_STD_VARIANT 1
578-
#else
579-
#error options.h is misconfigured.
580-
#endif
581-
582556
// ABSL_USES_STD_STRING_VIEW
583557
//
584558
// Indicates whether absl::string_view is an alias for std::string_view.
@@ -612,14 +586,6 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
612586
#error options.h is misconfigured.
613587
#endif
614588

615-
// In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
616-
// SEH exception from emplace for variant<SomeStruct> when constructing the
617-
// struct can throw. This defeats some of variant_test and
618-
// variant_exception_safety_test.
619-
#if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG)
620-
#define ABSL_INTERNAL_MSVC_2017_DBG_MODE
621-
#endif
622-
623589
// ABSL_INTERNAL_MANGLED_NS
624590
// ABSL_INTERNAL_MANGLED_BACKREFERENCE
625591
//

absl/base/options.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,32 +99,6 @@
9999

100100
#define ABSL_OPTION_USE_STD_STRING_VIEW 2
101101

102-
// ABSL_OPTION_USE_STD_VARIANT
103-
//
104-
// This option controls whether absl::variant is implemented as an alias to
105-
// std::variant, or as an independent implementation.
106-
//
107-
// A value of 0 means to use Abseil's implementation. This requires only C++11
108-
// support, and is expected to work on every toolchain we support.
109-
//
110-
// A value of 1 means to use an alias to std::variant. This requires that all
111-
// code using Abseil is built in C++17 mode or later.
112-
//
113-
// A value of 2 means to detect the C++ version being used to compile Abseil,
114-
// and use an alias only if a working std::variant is available. This option
115-
// is useful when you are building your program from source. It should not be
116-
// used otherwise -- for example, if you are distributing Abseil in a binary
117-
// package manager -- since in mode 2, absl::variant will name a different
118-
// type, with a different mangled name and binary layout, depending on the
119-
// compiler flags passed by the end user. For more info, see
120-
// https://abseil.io/about/design/dropin-types.
121-
//
122-
// User code should not inspect this macro. To check in the preprocessor if
123-
// absl::variant is a typedef of std::variant, use the feature macro
124-
// ABSL_USES_STD_VARIANT.
125-
126-
#define ABSL_OPTION_USE_STD_VARIANT 2
127-
128102
// ABSL_OPTION_USE_STD_ORDERING
129103
//
130104
// This option controls whether absl::{partial,weak,strong}_ordering are

absl/types/BUILD.bazel

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -105,81 +105,30 @@ cc_library(
105105
deprecation = "bad_optional_access dependency is empty can be removed",
106106
)
107107

108-
cc_library(
109-
name = "bad_variant_access",
110-
srcs = ["bad_variant_access.cc"],
111-
hdrs = ["bad_variant_access.h"],
112-
copts = ABSL_DEFAULT_COPTS,
113-
linkopts = ABSL_DEFAULT_LINKOPTS,
114-
deps = [
115-
"//absl/base:config",
116-
"//absl/base:raw_logging_internal",
117-
],
118-
)
119-
120108
cc_library(
121109
name = "variant",
122-
srcs = ["internal/variant.h"],
123110
hdrs = ["variant.h"],
124111
copts = ABSL_DEFAULT_COPTS,
125112
linkopts = ABSL_DEFAULT_LINKOPTS,
126113
deps = [
127-
":bad_variant_access",
128-
"//absl/base:base_internal",
129114
"//absl/base:config",
130-
"//absl/base:core_headers",
131-
"//absl/meta:type_traits",
132115
"//absl/utility",
133116
],
134117
)
135118

136-
cc_test(
137-
name = "variant_test",
138-
size = "small",
139-
srcs = ["variant_test.cc"],
140-
copts = ABSL_TEST_COPTS,
141-
linkopts = ABSL_DEFAULT_LINKOPTS,
142-
deps = [
143-
":variant",
144-
"//absl/base:config",
145-
"//absl/base:core_headers",
146-
"//absl/memory",
147-
"//absl/meta:type_traits",
148-
"//absl/strings",
149-
"@googletest//:gtest",
150-
"@googletest//:gtest_main",
151-
],
152-
)
153-
154-
cc_test(
155-
name = "variant_benchmark",
156-
srcs = [
157-
"variant_benchmark.cc",
158-
],
159-
copts = ABSL_TEST_COPTS,
160-
linkopts = ABSL_DEFAULT_LINKOPTS,
161-
tags = ["benchmark"],
162-
deps = [
163-
":variant",
164-
"//absl/utility",
165-
"@google_benchmark//:benchmark_main",
166-
"@googletest//:gtest",
167-
],
119+
cc_library(
120+
name = "bad_variant_access",
121+
deprecation = "bad_variant_access dependency is empty can be removed",
168122
)
169123

170124
cc_test(
171-
name = "variant_exception_safety_test",
125+
name = "variant_test",
172126
size = "small",
173-
srcs = [
174-
"variant_exception_safety_test.cc",
175-
],
127+
srcs = ["variant_test.cc"],
176128
copts = ABSL_TEST_COPTS,
177129
linkopts = ABSL_DEFAULT_LINKOPTS,
178130
deps = [
179131
":variant",
180-
"//absl/base:config",
181-
"//absl/base:exception_safety_testing",
182-
"//absl/memory",
183132
"@googletest//:gtest",
184133
"@googletest//:gtest_main",
185134
],

absl/types/CMakeLists.txt

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -100,36 +100,15 @@ absl_cc_library(
100100
PUBLIC
101101
)
102102

103-
absl_cc_library(
104-
NAME
105-
bad_variant_access
106-
HDRS
107-
"bad_variant_access.h"
108-
SRCS
109-
"bad_variant_access.cc"
110-
COPTS
111-
${ABSL_DEFAULT_COPTS}
112-
DEPS
113-
absl::config
114-
absl::raw_logging_internal
115-
PUBLIC
116-
)
117-
118103
absl_cc_library(
119104
NAME
120105
variant
121106
HDRS
122107
"variant.h"
123-
SRCS
124-
"internal/variant.h"
125108
COPTS
126109
${ABSL_DEFAULT_COPTS}
127110
DEPS
128-
absl::bad_variant_access
129-
absl::base_internal
130111
absl::config
131-
absl::core_headers
132-
absl::type_traits
133112
absl::utility
134113
PUBLIC
135114
)
@@ -143,11 +122,6 @@ absl_cc_test(
143122
${ABSL_TEST_COPTS}
144123
DEPS
145124
absl::variant
146-
absl::config
147-
absl::core_headers
148-
absl::memory
149-
absl::type_traits
150-
absl::strings
151125
GTest::gmock_main
152126
)
153127

@@ -177,18 +151,3 @@ absl_cc_test(
177151
absl::compare
178152
GTest::gmock_main
179153
)
180-
181-
absl_cc_test(
182-
NAME
183-
variant_exception_safety_test
184-
SRCS
185-
"variant_exception_safety_test.cc"
186-
COPTS
187-
${ABSL_TEST_COPTS}
188-
DEPS
189-
absl::variant
190-
absl::config
191-
absl::exception_safety_testing
192-
absl::memory
193-
GTest::gmock_main
194-
)

absl/types/bad_variant_access.cc

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)