Export of internal Abseil changes
-- 2f49cb9009386bc67bf54a2908c8720b749c8b7f by Greg Falcon <gfalcon@google.com>: docs: fix typo Import of https://github.com/abseil/abseil-cpp/pull/397 PiperOrigin-RevId: 277504420 -- f2bed362c1c12d3fa9c22d11f2b918668e8c37b7 by Abseil Team <absl-team@google.com>: Avoid our is_[copy/move]_assignable workarounds in MSVC 19.20 and on, since that release introduces a regression that breaks our workaround. We should ideally use the std forms in more cases, but branching when our workarounds fail is simpler to maintain. PiperOrigin-RevId: 277502334 -- e33de894ffd49848b9e088f59acc9743d1661948 by Derek Mauro <dmauro@google.com>: Update rules_cc version. The mirror.bazel.build URL does not exist (cache expiration?) PiperOrigin-RevId: 277498394 -- b23757b0747c64634d2d701433782c969effef19 by Abseil Team <absl-team@google.com>: Fix https://github.com/abseil/abseil-cpp/issues/394. PiperOrigin-RevId: 277491405 -- 54c75b8b29813531c52d67cf0ba7063baae4a4f3 by Abseil Team <absl-team@google.com>: Fix comment typos: waker => waiter. PiperOrigin-RevId: 277376952 -- 874eeaa3b3af808fc88b6355245f643674f5e36e by Abseil Team <absl-team@google.com>: Don't use atomic ops on waiter and wakeup counts in CONDVAR waiter mode. Just guard the waiter and wakeup counts with the mutex. This eliminates the race. Also fix a typo in the error message for pthread_cond_timedwait. PiperOrigin-RevId: 277366017 -- ce8c9a63109214519b5a7eaecef2c663c4d566df by Greg Falcon <gfalcon@google.com>: Implement the config options for our four main C++ forward compatibility types. These options control whether the names `any`, `optional`, `string_view`, and `variant` in namespace `absl` are aliases to the corresponding C++17 types in namespace `std`. By default, we continue to auto-detect the configuration of the compiler being run. These options are not intended to be modified on the command line (as -D flags, say). Instead, the options.h file can be modified by distributors of Abseil (e.g., binary packagers, maintainers of local copies of Abseil, etc.) Changing options will change Abseil in an ODR sense. Any program must only link in a single version of Abseil. Linking libraries that use Abseil configured with different options is an error: there is no ABI compatibility guarantee when linking different configurations, even if the Abseil versions used are otherwise exactly identical. PiperOrigin-RevId: 277364298 -- 5ed3ad42ae43a05862070f92f9ffd07f5c1f2b81 by Chris Kennelly <ckennelly@google.com>: Suppress -Wimplicit-int-float-conversion. On recent builds of Clang, this is an error/warning. PiperOrigin-RevId: 277346168 -- 9b9b0055243c705189bb27d912e6d45a7789cdee by Eric Fiselier <ericwf@google.com>: Allow building Abseil as a shared library with CMake. By default CMake's `add_library` creates the target as a static library. However, users can override the default using the builtin CMake option -DBUILD_SHARED_LIBS=ON. This changes Abseil's CMake to respect this configuration option by removing the explicit `STATIC` in our usages of `add_library`. PiperOrigin-RevId: 277337753 -- 63a8b7b8ede3a9d851916929d6b8537f4f2508ca by Abseil Team <absl-team@google.com>: Improve AlphaNum Hex performance by using absl::numbers_internal::FastHexToBufferZeroPad16. PiperOrigin-RevId: 277318108 -- dd047f7e92032682d94b27732df0e4d0670e24a4 by CJ Johnson <johnsoncj@google.com>: Internal change PiperOrigin-RevId: 277316913 -- d19ee7074929fed08973cc5b40a844573ce1e0a6 by Abseil Team <absl-team@google.com>: Handle invoking [[nodiscard]] functions correctly in our tests. PiperOrigin-RevId: 277301500 -- 5373f3737894ba9b8481e95e5f58c7957c00d26a by Chris Kennelly <ckennelly@google.com>: For internal reasons, loosen visibility restrictions of `//absl/base:malloc_internal`. As an internal-namespace interface, this module remains unsupported. We reserve the right to change, delete, or re-restrict visibility to this target at any time. PiperOrigin-RevId: 277118689 -- 44e4f6655e05393a375d09b3625c192b1fde5909 by Abseil Team <absl-team@google.com>: Fix error in example civil day comment. PiperOrigin-RevId: 277103315 -- 7657392b4ce48469106f11cdb952a0bc76a28df3 by Abseil Team <absl-team@google.com>: Internal change PiperOrigin-RevId: 277056076 -- c75bda76f40b01fa249b75b5a70c1f5907e56c76 by Abseil Team <absl-team@google.com>: Suppress lifetime constant-initialization tests when building with MSVC versions > 19.0. These are broken due to non-compliant initialization order in these versions: https://developercommunity.visualstudio.com/content/problem/336946/class-with-constexpr-constructor-not-using-static.html We don't know when Microsoft will fix this bug. PiperOrigin-RevId: 277049770 -- 16c3b9bf2a1796efa57f97b00bcd6227fbccca1f by Matt Calabrese <calabrese@google.com>: Avoid our is_[copy/move]_assignable workarounds in MSVC 19.20 and on, since that release introduces a regression that breaks our workaround. We should ideally use the std forms in more cases, but branching when our workarounds fail is simpler to maintain. PiperOrigin-RevId: 277048670 -- e91003fa3ee6026d9b80624a23fc144fa5d74810 by Chris Kennelly <ckennelly@google.com>: Fix -Wimplicit-int-float-conversion warning in latest clang PiperOrigin-RevId: 276771618 -- 53087ca6603e86ad815f3dd9ab795cc0f79792c1 by Andy Soffer <asoffer@google.com>: Add documentation on absl::SNPrintF. PiperOrigin-RevId: 276694032 -- a9426af8cbd4c3a8f9053e7446c821852e41ff61 by Jorg Brown <jorg@google.com>: Stop including kern/OSByteOrder.h in order to support __APPLE__ Apple compiles with clang now anyway, and clang has support for the built-in compiler swap functions that are much faster than any function call to the OS. PiperOrigin-RevId: 276625231 -- df974be5aa5b4dc1b09c356cb8816edfc7867e63 by Jorg Brown <jorg@google.com>: Fix the build for Android x86-64 builds, where __SSE4_2__ is defined but _bswap64 is not. PiperOrigin-RevId: 276542642 -- d99dc092b3a5ad17643005e55f3b3cb6b9187ccc by Jorg Brown <jorg@google.com>: Remove a byteswap from the non-SSE path of FastHexToBufferZeroPad16 Remove the need for including absl/base/internal/endian.h from the SSE case (since if we have the Intel SSE intrinsics, then clearly we also have the Intel Byte-Swap intrinsics.) PiperOrigin-RevId: 276532608 -- d67b106dc930d8558810ae3983613bb2ab1e0d36 by Abseil Team <absl-team@google.com>: Use explicit static_cast<double> for int64_t to double conversion This uses an explicit static_cast<double>() in the int64_t to double comparisons in duration.cc's SafeAddRepHi. This satisfies clang's -Wimplicit-int-to-float-conversion warning (with https://reviews.llvm.org/D64666). This may also make it easier for humans to realize that the comparison is happening between two floating point double precision values. It should have no impact on the behavior or generated code. Tested: No behavior change PiperOrigin-RevId: 276529211 GitOrigin-RevId: 2f49cb9009386bc67bf54a2908c8720b749c8b7f Change-Id: I71e0781893ce219960b8290d54b20532779cb0ff
This commit is contained in:
parent
078b89b3c0
commit
8207907f4f
42 changed files with 458 additions and 188 deletions
|
@ -104,7 +104,10 @@ function(absl_cc_library)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT ABSL_CC_LIB_IS_INTERFACE)
|
if(NOT ABSL_CC_LIB_IS_INTERFACE)
|
||||||
add_library(${_NAME} STATIC "")
|
# CMake creates static libraries by default. Users can specify
|
||||||
|
# -DBUILD_SHARED_LIBS=ON during initial configuration to build shared
|
||||||
|
# libraries instead.
|
||||||
|
add_library(${_NAME} "")
|
||||||
target_sources(${_NAME} PRIVATE ${ABSL_CC_LIB_SRCS} ${ABSL_CC_LIB_HDRS})
|
target_sources(${_NAME} PRIVATE ${ABSL_CC_LIB_SRCS} ${ABSL_CC_LIB_HDRS})
|
||||||
target_include_directories(${_NAME}
|
target_include_directories(${_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
|
|
@ -36,10 +36,10 @@ http_archive(
|
||||||
# C++ rules for Bazel.
|
# C++ rules for Bazel.
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "rules_cc",
|
name = "rules_cc",
|
||||||
sha256 = "67412176974bfce3f4cf8bdaff39784a72ed709fc58def599d1f68710b58d68b",
|
sha256 = "9a446e9dd9c1bb180c86977a8dc1e9e659550ae732ae58bd2e8fd51e15b2c91d",
|
||||||
strip_prefix = "rules_cc-b7fe9697c0c76ab2fd431a891dbb9a6a32ed7c3e",
|
strip_prefix = "rules_cc-262ebec3c2296296526740db4aefce68c80de7fa",
|
||||||
urls = [
|
urls = [
|
||||||
"https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/b7fe9697c0c76ab2fd431a891dbb9a6a32ed7c3e.zip",
|
"https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/262ebec3c2296296526740db4aefce68c80de7fa.zip",
|
||||||
"https://github.com/bazelbuild/rules_cc/archive/b7fe9697c0c76ab2fd431a891dbb9a6a32ed7c3e.zip",
|
"https://github.com/bazelbuild/rules_cc/archive/262ebec3c2296296526740db4aefce68c80de7fa.zip",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -87,6 +87,7 @@ cc_library(
|
||||||
name = "config",
|
name = "config",
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"config.h",
|
"config.h",
|
||||||
|
"options.h",
|
||||||
"policy_checks.h",
|
"policy_checks.h",
|
||||||
],
|
],
|
||||||
copts = ABSL_DEFAULT_COPTS,
|
copts = ABSL_DEFAULT_COPTS,
|
||||||
|
@ -137,7 +138,7 @@ cc_library(
|
||||||
"//conditions:default": ["-pthread"],
|
"//conditions:default": ["-pthread"],
|
||||||
}) + ABSL_DEFAULT_LINKOPTS,
|
}) + ABSL_DEFAULT_LINKOPTS,
|
||||||
visibility = [
|
visibility = [
|
||||||
"//absl:__subpackages__",
|
"//visibility:public",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":base",
|
":base",
|
||||||
|
|
|
@ -75,6 +75,7 @@ absl_cc_library(
|
||||||
config
|
config
|
||||||
HDRS
|
HDRS
|
||||||
"config.h"
|
"config.h"
|
||||||
|
"options.h"
|
||||||
"policy_checks.h"
|
"policy_checks.h"
|
||||||
COPTS
|
COPTS
|
||||||
${ABSL_DEFAULT_COPTS}
|
${ABSL_DEFAULT_COPTS}
|
||||||
|
|
|
@ -63,6 +63,7 @@
|
||||||
#include <TargetConditionals.h>
|
#include <TargetConditionals.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "absl/base/options.h"
|
||||||
#include "absl/base/policy_checks.h"
|
#include "absl/base/policy_checks.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -468,6 +469,68 @@
|
||||||
#define ABSL_HAVE_STD_STRING_VIEW 1
|
#define ABSL_HAVE_STD_STRING_VIEW 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// ABSL_USES_STD_ANY
|
||||||
|
//
|
||||||
|
// Indicates whether absl::any is an alias for std::any.
|
||||||
|
#if !defined(ABSL_OPTION_USE_STD_ANY)
|
||||||
|
#error options.h is misconfigured.
|
||||||
|
#elif ABSL_OPTION_USE_STD_ANY == 0 || \
|
||||||
|
(ABSL_OPTION_USE_STD_ANY == 2 && !defined(ABSL_HAVE_STD_ANY))
|
||||||
|
#undef ABSL_USES_STD_ANY
|
||||||
|
#elif ABSL_OPTION_USE_STD_ANY == 1 || \
|
||||||
|
(ABSL_OPTION_USE_STD_ANY == 2 && defined(ABSL_HAVE_STD_ANY))
|
||||||
|
#define ABSL_USES_STD_ANY 1
|
||||||
|
#else
|
||||||
|
#error options.h is misconfigured.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ABSL_USES_STD_OPTIONAL
|
||||||
|
//
|
||||||
|
// Indicates whether absl::optional is an alias for std::optional.
|
||||||
|
#if !defined(ABSL_OPTION_USE_STD_OPTIONAL)
|
||||||
|
#error options.h is misconfigured.
|
||||||
|
#elif ABSL_OPTION_USE_STD_OPTIONAL == 0 || \
|
||||||
|
(ABSL_OPTION_USE_STD_OPTIONAL == 2 && !defined(ABSL_HAVE_STD_OPTIONAL))
|
||||||
|
#undef ABSL_USES_STD_OPTIONAL
|
||||||
|
#elif ABSL_OPTION_USE_STD_OPTIONAL == 1 || \
|
||||||
|
(ABSL_OPTION_USE_STD_OPTIONAL == 2 && defined(ABSL_HAVE_STD_OPTIONAL))
|
||||||
|
#define ABSL_USES_STD_OPTIONAL 1
|
||||||
|
#else
|
||||||
|
#error options.h is misconfigured.
|
||||||
|
#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.
|
||||||
|
#if !defined(ABSL_OPTION_USE_STD_STRING_VIEW)
|
||||||
|
#error options.h is misconfigured.
|
||||||
|
#elif ABSL_OPTION_USE_STD_STRING_VIEW == 0 || \
|
||||||
|
(ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
|
||||||
|
!defined(ABSL_HAVE_STD_STRING_VIEW))
|
||||||
|
#undef ABSL_USES_STD_STRING_VIEW
|
||||||
|
#elif ABSL_OPTION_USE_STD_STRING_VIEW == 1 || \
|
||||||
|
(ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
|
||||||
|
defined(ABSL_HAVE_STD_STRING_VIEW))
|
||||||
|
#define ABSL_USES_STD_STRING_VIEW 1
|
||||||
|
#else
|
||||||
|
#error options.h is misconfigured.
|
||||||
|
#endif
|
||||||
|
|
||||||
// In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
|
// In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
|
||||||
// SEH exception from emplace for variant<SomeStruct> when constructing the
|
// SEH exception from emplace for variant<SomeStruct> when constructing the
|
||||||
// struct can throw. This defeats some of variant_test and
|
// struct can throw. This defeats some of variant_test and
|
||||||
|
|
|
@ -19,9 +19,6 @@
|
||||||
// The following guarantees declaration of the byte swap functions
|
// The following guarantees declaration of the byte swap functions
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <stdlib.h> // NOLINT(build/include)
|
#include <stdlib.h> // NOLINT(build/include)
|
||||||
#elif defined(__APPLE__)
|
|
||||||
// macOS / Darwin features
|
|
||||||
#include <libkern/OSByteOrder.h>
|
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__)
|
||||||
#include <sys/endian.h>
|
#include <sys/endian.h>
|
||||||
#elif defined(__GLIBC__)
|
#elif defined(__GLIBC__)
|
||||||
|
@ -63,11 +60,6 @@ inline uint16_t gbswap_16(uint16_t host_int) {
|
||||||
return _byteswap_ushort(host_int);
|
return _byteswap_ushort(host_int);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
inline uint64_t gbswap_64(uint64_t host_int) { return OSSwapInt16(host_int); }
|
|
||||||
inline uint32_t gbswap_32(uint32_t host_int) { return OSSwapInt32(host_int); }
|
|
||||||
inline uint16_t gbswap_16(uint16_t host_int) { return OSSwapInt64(host_int); }
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
inline uint64_t gbswap_64(uint64_t host_int) {
|
inline uint64_t gbswap_64(uint64_t host_int) {
|
||||||
#if defined(__GNUC__) && defined(__x86_64__) && !defined(__APPLE__)
|
#if defined(__GNUC__) && defined(__x86_64__) && !defined(__APPLE__)
|
||||||
|
|
188
absl/base/options.h
Normal file
188
absl/base/options.h
Normal file
|
@ -0,0 +1,188 @@
|
||||||
|
#ifndef ABSL_BASE_OPTIONS_H_
|
||||||
|
#define ABSL_BASE_OPTIONS_H_
|
||||||
|
|
||||||
|
// Copyright 2019 The Abseil Authors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// File: options.h
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This file contains Abseil configuration options for setting specific
|
||||||
|
// implementations instead of letting Abseil determine which implementation to
|
||||||
|
// use at compile-time. Setting these options may be useful for package or build
|
||||||
|
// managers who wish to guarantee ABI stability within binary builds (which are
|
||||||
|
// otherwise difficult to enforce).
|
||||||
|
//
|
||||||
|
// *** IMPORTANT NOTICE FOR PACKAGE MANAGERS: It is important that
|
||||||
|
// maintainers of package managers who wish to package Abseil read and
|
||||||
|
// understand this file! ***
|
||||||
|
//
|
||||||
|
// Abseil contains a number of possible configuration endpoints, based on
|
||||||
|
// parameters such as the detected platform, language version, or command-line
|
||||||
|
// flags used to invoke the underlying binary. As is the case with all
|
||||||
|
// libraries, binaries which contain Abseil code must ensure that separate
|
||||||
|
// packages use the same compiled copy of Abseil to avoid a diamond dependency
|
||||||
|
// problem, which can occur if two packages built with different Abseil
|
||||||
|
// configuration settings are linked together. Diamond dependency problems in
|
||||||
|
// C++ may manifest as violations to the One Definition Rule (ODR) (resulting in
|
||||||
|
// linker errors), or undefined behavior (resulting in crashes).
|
||||||
|
//
|
||||||
|
// Diamond dependency problems can be avoided if all packages utilize the same
|
||||||
|
// exact version of Abseil. Building from source code with the same compilation
|
||||||
|
// parameters is the easiest way to avoid such dependency problems. However, for
|
||||||
|
// package managers who cannot control such compilation parameters, we are
|
||||||
|
// providing the file to allow you to inject ABI (Application Binary Interface)
|
||||||
|
// stability across builds. Settings options in this file will neither change
|
||||||
|
// API nor ABI, providing a stable copy of Abseil between packages.
|
||||||
|
//
|
||||||
|
// Care must be taken to keep options within these configurations isolated
|
||||||
|
// from any other dynamic settings, such as command-line flags which could alter
|
||||||
|
// these options. This file is provided specifically to help build and package
|
||||||
|
// managers provide a stable copy of Abseil within their libraries and binaries;
|
||||||
|
// other developers should not have need to alter the contents of this file.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Usage
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// For any particular package release, set the appropriate definitions within
|
||||||
|
// this file to whatever value makes the most sense for your package(s). Note
|
||||||
|
// that, by default, most of these options, at the moment, affect the
|
||||||
|
// implementation of types; future options may affect other implementation
|
||||||
|
// details.
|
||||||
|
//
|
||||||
|
// NOTE: the defaults within this file all assume that Abseil can select the
|
||||||
|
// proper Abseil implementation at compile-time, which will not be sufficient
|
||||||
|
// to guarantee ABI stability to package managers.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Type Compatibility Options
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// ABSL_OPTION_USE_STD_ANY
|
||||||
|
//
|
||||||
|
// This option controls whether absl::any is implemented as an alias to
|
||||||
|
// std::any, 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::any. 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::any is available. This option is
|
||||||
|
// useful when you are building your entire program, including all of its
|
||||||
|
// dependencies, 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::any 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::any is a typedef of std::any, use the feature macro ABSL_USES_STD_ANY.
|
||||||
|
|
||||||
|
#define ABSL_OPTION_USE_STD_ANY 2
|
||||||
|
|
||||||
|
|
||||||
|
// ABSL_OPTION_USE_STD_OPTIONAL
|
||||||
|
//
|
||||||
|
// This option controls whether absl::optional is implemented as an alias to
|
||||||
|
// std::optional, 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::optional. 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::optional 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::optional 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.
|
||||||
|
|
||||||
|
// A value of 2 means to detect the C++ version being used to compile Abseil,
|
||||||
|
// and use an alias only if a working std::optional is available. This option
|
||||||
|
// should not be used when your program is not built from source -- for example,
|
||||||
|
// if you are distributing Abseil in a binary package manager -- since in mode
|
||||||
|
// 2, absl::optional will name a different template class, with a different
|
||||||
|
// mangled name and binary layout, depending on the compiler flags passed by the
|
||||||
|
// end user.
|
||||||
|
//
|
||||||
|
// User code should not inspect this macro. To check in the preprocessor if
|
||||||
|
// absl::optional is a typedef of std::optional, use the feature macro
|
||||||
|
// ABSL_USES_STD_OPTIONAL.
|
||||||
|
|
||||||
|
#define ABSL_OPTION_USE_STD_OPTIONAL 2
|
||||||
|
|
||||||
|
|
||||||
|
// ABSL_OPTION_USE_STD_STRING_VIEW
|
||||||
|
//
|
||||||
|
// This option controls whether absl::string_view is implemented as an alias to
|
||||||
|
// std::string_view, 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::string_view. 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::string_view 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::string_view 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::string_view is a typedef of std::string_view, use the feature macro
|
||||||
|
// ABSL_USES_STD_STRING_VIEW.
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
#endif // ABSL_BASE_OPTIONS_H_
|
|
@ -214,7 +214,7 @@ TEST(FlatHashMap, MergeExtractInsert) {
|
||||||
EXPECT_THAT(m, UnorderedElementsAre(Pair(1, 17), Pair(2, 9)));
|
EXPECT_THAT(m, UnorderedElementsAre(Pair(1, 17), Pair(2, 9)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined(ABSL_HAVE_STD_ANY) || !defined(_LIBCPP_VERSION)) && \
|
#if (defined(ABSL_USES_STD_ANY) || !defined(_LIBCPP_VERSION)) && \
|
||||||
!defined(__EMSCRIPTEN__)
|
!defined(__EMSCRIPTEN__)
|
||||||
TEST(FlatHashMap, Any) {
|
TEST(FlatHashMap, Any) {
|
||||||
absl::flat_hash_map<int, absl::any> m;
|
absl::flat_hash_map<int, absl::any> m;
|
||||||
|
@ -246,7 +246,7 @@ TEST(FlatHashMap, Any) {
|
||||||
ASSERT_NE(it2, m2.end());
|
ASSERT_NE(it2, m2.end());
|
||||||
EXPECT_EQ(7, it2->second);
|
EXPECT_EQ(7, it2->second);
|
||||||
}
|
}
|
||||||
#endif // (defined(ABSL_HAVE_STD_ANY) || !defined(_LIBCPP_VERSION)) &&
|
#endif // (defined(ABSL_USES_STD_ANY) || !defined(_LIBCPP_VERSION)) &&
|
||||||
// !defined(__EMSCRIPTEN__)
|
// !defined(__EMSCRIPTEN__)
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -471,12 +471,9 @@ auto Storage<T, N, A>::Initialize(ValueAdapter values, size_type new_size)
|
||||||
// safe to take on the allocation with size `0`. If `ConstructElements(...)`
|
// safe to take on the allocation with size `0`. If `ConstructElements(...)`
|
||||||
// throws, deallocation will be automatically handled by `~Storage()`.
|
// throws, deallocation will be automatically handled by `~Storage()`.
|
||||||
size_type new_capacity = ComputeCapacity(GetInlinedCapacity(), new_size);
|
size_type new_capacity = ComputeCapacity(GetInlinedCapacity(), new_size);
|
||||||
pointer new_data = AllocatorTraits::allocate(*GetAllocPtr(), new_capacity);
|
construct_data = AllocatorTraits::allocate(*GetAllocPtr(), new_capacity);
|
||||||
|
SetAllocatedData(construct_data, new_capacity);
|
||||||
SetAllocatedData(new_data, new_capacity);
|
|
||||||
SetIsAllocated();
|
SetIsAllocated();
|
||||||
|
|
||||||
construct_data = new_data;
|
|
||||||
} else {
|
} else {
|
||||||
construct_data = GetInlinedData();
|
construct_data = GetInlinedData();
|
||||||
}
|
}
|
||||||
|
@ -503,9 +500,7 @@ auto Storage<T, N, A>::Assign(ValueAdapter values, size_type new_size) -> void {
|
||||||
|
|
||||||
if (new_size > storage_view.capacity) {
|
if (new_size > storage_view.capacity) {
|
||||||
size_type new_capacity = ComputeCapacity(storage_view.capacity, new_size);
|
size_type new_capacity = ComputeCapacity(storage_view.capacity, new_size);
|
||||||
pointer new_data = allocation_tx.Allocate(new_capacity);
|
construct_loop = {allocation_tx.Allocate(new_capacity), new_size};
|
||||||
|
|
||||||
construct_loop = {new_data, new_size};
|
|
||||||
destroy_loop = {storage_view.data, storage_view.size};
|
destroy_loop = {storage_view.data, storage_view.size};
|
||||||
} else if (new_size > storage_view.size) {
|
} else if (new_size > storage_view.size) {
|
||||||
assign_loop = {storage_view.data, storage_view.size};
|
assign_loop = {storage_view.data, storage_view.size};
|
||||||
|
@ -552,7 +547,6 @@ auto Storage<T, N, A>::Resize(ValueAdapter values, size_type new_size) -> void {
|
||||||
if (new_size > storage_view.capacity) {
|
if (new_size > storage_view.capacity) {
|
||||||
size_type new_capacity = ComputeCapacity(storage_view.capacity, new_size);
|
size_type new_capacity = ComputeCapacity(storage_view.capacity, new_size);
|
||||||
pointer new_data = allocation_tx.Allocate(new_capacity);
|
pointer new_data = allocation_tx.Allocate(new_capacity);
|
||||||
|
|
||||||
construct_loop = {new_data + storage_view.size,
|
construct_loop = {new_data + storage_view.size,
|
||||||
new_size - storage_view.size};
|
new_size - storage_view.size};
|
||||||
move_construct_loop = {new_data, storage_view.size};
|
move_construct_loop = {new_data, storage_view.size};
|
||||||
|
@ -690,14 +684,14 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference {
|
||||||
pointer construct_data;
|
pointer construct_data;
|
||||||
if (storage_view.size == storage_view.capacity) {
|
if (storage_view.size == storage_view.capacity) {
|
||||||
size_type new_capacity = NextCapacity(storage_view.capacity);
|
size_type new_capacity = NextCapacity(storage_view.capacity);
|
||||||
pointer new_data = allocation_tx.Allocate(new_capacity);
|
construct_data = allocation_tx.Allocate(new_capacity);
|
||||||
|
|
||||||
construct_data = new_data;
|
|
||||||
} else {
|
} else {
|
||||||
construct_data = storage_view.data;
|
construct_data = storage_view.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
AllocatorTraits::construct(*GetAllocPtr(), construct_data + storage_view.size,
|
pointer last_ptr = construct_data + storage_view.size;
|
||||||
|
|
||||||
|
AllocatorTraits::construct(*GetAllocPtr(), last_ptr,
|
||||||
std::forward<Args>(args)...);
|
std::forward<Args>(args)...);
|
||||||
|
|
||||||
if (allocation_tx.DidAllocate()) {
|
if (allocation_tx.DidAllocate()) {
|
||||||
|
@ -707,8 +701,7 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference {
|
||||||
storage_view.size);
|
storage_view.size);
|
||||||
}
|
}
|
||||||
ABSL_INTERNAL_CATCH_ANY {
|
ABSL_INTERNAL_CATCH_ANY {
|
||||||
AllocatorTraits::destroy(*GetAllocPtr(),
|
AllocatorTraits::destroy(*GetAllocPtr(), last_ptr);
|
||||||
construct_data + storage_view.size);
|
|
||||||
ABSL_INTERNAL_RETHROW;
|
ABSL_INTERNAL_RETHROW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -721,7 +714,7 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
AddSize(1);
|
AddSize(1);
|
||||||
return *(construct_data + storage_view.size);
|
return *last_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, size_t N, typename A>
|
template <typename T, size_t N, typename A>
|
||||||
|
@ -793,9 +786,7 @@ auto Storage<T, N, A>::ShrinkToFit() -> void {
|
||||||
pointer construct_data;
|
pointer construct_data;
|
||||||
if (storage_view.size > GetInlinedCapacity()) {
|
if (storage_view.size > GetInlinedCapacity()) {
|
||||||
size_type new_capacity = storage_view.size;
|
size_type new_capacity = storage_view.size;
|
||||||
pointer new_data = allocation_tx.Allocate(new_capacity);
|
construct_data = allocation_tx.Allocate(new_capacity);
|
||||||
|
|
||||||
construct_data = new_data;
|
|
||||||
} else {
|
} else {
|
||||||
construct_data = GetInlinedData();
|
construct_data = GetInlinedData();
|
||||||
}
|
}
|
||||||
|
|
|
@ -668,7 +668,7 @@ class raw_hash_set {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrl_t* ctrl_ = nullptr;
|
ctrl_t* ctrl_ = nullptr;
|
||||||
// To avoid uninitialized member warnigs, put slot_ in an anonymous union.
|
// To avoid uninitialized member warnings, put slot_ in an anonymous union.
|
||||||
// The member is not initialized on singleton and end iterators.
|
// The member is not initialized on singleton and end iterators.
|
||||||
union {
|
union {
|
||||||
slot_type* slot_;
|
slot_type* slot_;
|
||||||
|
|
|
@ -145,6 +145,18 @@ using IsMoveAssignableImpl = decltype(std::declval<T&>() = std::declval<T&&>());
|
||||||
|
|
||||||
} // namespace type_traits_internal
|
} // namespace type_traits_internal
|
||||||
|
|
||||||
|
// MSVC 19.20 has a regression that causes our workarounds to fail, but their
|
||||||
|
// std forms now appear to be compliant.
|
||||||
|
#if defined(_MSC_VER) && !defined(__clang__) && (_MSC_VER >= 1920)
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using is_copy_assignable = std::is_copy_assignable<T>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using is_move_assignable = std::is_move_assignable<T>;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_copy_assignable : type_traits_internal::is_detected<
|
struct is_copy_assignable : type_traits_internal::is_detected<
|
||||||
type_traits_internal::IsCopyAssignableImpl, T> {
|
type_traits_internal::IsCopyAssignableImpl, T> {
|
||||||
|
@ -155,6 +167,8 @@ struct is_move_assignable : type_traits_internal::is_detected<
|
||||||
type_traits_internal::IsMoveAssignableImpl, T> {
|
type_traits_internal::IsMoveAssignableImpl, T> {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// void_t()
|
// void_t()
|
||||||
//
|
//
|
||||||
// Ignores the type of any its arguments and returns `void`. In general, this
|
// Ignores the type of any its arguments and returns `void`. In general, this
|
||||||
|
|
|
@ -154,9 +154,10 @@ TEST(NonsecureURBGBase, CompatibleWithDistributionUtils) {
|
||||||
TEST(NonsecureURBGBase, CompatibleWithStdDistributions) {
|
TEST(NonsecureURBGBase, CompatibleWithStdDistributions) {
|
||||||
ExampleNonsecureURBG rbg;
|
ExampleNonsecureURBG rbg;
|
||||||
|
|
||||||
std::uniform_int_distribution<uint32_t>(0, 100)(rbg);
|
// Cast to void to suppress [[nodiscard]] warnings
|
||||||
std::uniform_real_distribution<float>()(rbg);
|
static_cast<void>(std::uniform_int_distribution<uint32_t>(0, 100)(rbg));
|
||||||
std::bernoulli_distribution(0.2)(rbg);
|
static_cast<void>(std::uniform_real_distribution<float>()(rbg));
|
||||||
|
static_cast<void>(std::bernoulli_distribution(0.2)(rbg));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NonsecureURBGBase, ConsecutiveDefaultInstancesYieldUniqueVariates) {
|
TEST(NonsecureURBGBase, ConsecutiveDefaultInstancesYieldUniqueVariates) {
|
||||||
|
|
|
@ -192,11 +192,13 @@ log_uniform_int_distribution<IntType>::Generate(
|
||||||
const double r = std::pow(p.base(), d);
|
const double r = std::pow(p.base(), d);
|
||||||
const double s = (r * p.base()) - 1.0;
|
const double s = (r * p.base()) - 1.0;
|
||||||
|
|
||||||
base_e = (r > (std::numeric_limits<unsigned_type>::max)())
|
base_e =
|
||||||
|
(r > static_cast<double>((std::numeric_limits<unsigned_type>::max)()))
|
||||||
? (std::numeric_limits<unsigned_type>::max)()
|
? (std::numeric_limits<unsigned_type>::max)()
|
||||||
: static_cast<unsigned_type>(r);
|
: static_cast<unsigned_type>(r);
|
||||||
|
|
||||||
top_e = (s > (std::numeric_limits<unsigned_type>::max)())
|
top_e =
|
||||||
|
(s > static_cast<double>((std::numeric_limits<unsigned_type>::max)()))
|
||||||
? (std::numeric_limits<unsigned_type>::max)()
|
? (std::numeric_limits<unsigned_type>::max)()
|
||||||
: static_cast<unsigned_type>(s);
|
: static_cast<unsigned_type>(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,14 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "absl/base/internal/bits.h"
|
#include "absl/base/internal/bits.h"
|
||||||
|
#ifdef __SSE4_2__
|
||||||
|
// TODO(jorg): Remove this when we figure out the right way
|
||||||
|
// to swap bytes on SSE 4.2 that works with the compilers
|
||||||
|
// we claim to support. Also, add tests for the compiler
|
||||||
|
// that doesn't support the Intel _bswap64 intrinsic but
|
||||||
|
// does support all the SSE 4.2 intrinsics
|
||||||
#include "absl/base/internal/endian.h"
|
#include "absl/base/internal/endian.h"
|
||||||
|
#endif
|
||||||
#include "absl/base/macros.h"
|
#include "absl/base/macros.h"
|
||||||
#include "absl/base/port.h"
|
#include "absl/base/port.h"
|
||||||
#include "absl/numeric/int128.h"
|
#include "absl/numeric/int128.h"
|
||||||
|
@ -189,12 +196,12 @@ ABSL_MUST_USE_RESULT bool safe_strtoi_base(absl::string_view s, int_type* out,
|
||||||
// Returns the number of non-pad digits of the output (it can never be zero
|
// Returns the number of non-pad digits of the output (it can never be zero
|
||||||
// since 0 has one digit).
|
// since 0 has one digit).
|
||||||
inline size_t FastHexToBufferZeroPad16(uint64_t val, char* out) {
|
inline size_t FastHexToBufferZeroPad16(uint64_t val, char* out) {
|
||||||
uint64_t be = absl::big_endian::FromHost64(val);
|
|
||||||
#ifdef __SSE4_2__
|
#ifdef __SSE4_2__
|
||||||
|
uint64_t be = absl::big_endian::FromHost64(val);
|
||||||
const auto kNibbleMask = _mm_set1_epi8(0xf);
|
const auto kNibbleMask = _mm_set1_epi8(0xf);
|
||||||
const auto kHexDigits = _mm_setr_epi8('0', '1', '2', '3', '4', '5', '6', '7',
|
const auto kHexDigits = _mm_setr_epi8('0', '1', '2', '3', '4', '5', '6', '7',
|
||||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
|
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
|
||||||
auto v = _mm_loadu_si64(reinterpret_cast<__m128i*>(&be)); // load lo dword
|
auto v = _mm_loadl_epi64(reinterpret_cast<__m128i*>(&be)); // load lo dword
|
||||||
auto v4 = _mm_srli_epi64(v, 4); // shift 4 right
|
auto v4 = _mm_srli_epi64(v, 4); // shift 4 right
|
||||||
auto il = _mm_unpacklo_epi8(v4, v); // interleave bytes
|
auto il = _mm_unpacklo_epi8(v4, v); // interleave bytes
|
||||||
auto m = _mm_and_si128(il, kNibbleMask); // mask out nibbles
|
auto m = _mm_and_si128(il, kNibbleMask); // mask out nibbles
|
||||||
|
@ -202,7 +209,7 @@ inline size_t FastHexToBufferZeroPad16(uint64_t val, char* out) {
|
||||||
_mm_storeu_si128(reinterpret_cast<__m128i*>(out), hexchars);
|
_mm_storeu_si128(reinterpret_cast<__m128i*>(out), hexchars);
|
||||||
#else
|
#else
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
auto byte = (be >> (8 * i)) & 0xFF;
|
auto byte = (val >> (56 - 8 * i)) & 0xFF;
|
||||||
auto* hex = &absl::numbers_internal::kHexTable[byte * 2];
|
auto* hex = &absl::numbers_internal::kHexTable[byte * 2];
|
||||||
std::memcpy(out + 2 * i, hex, 2);
|
std::memcpy(out + 2 * i, hex, 2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,23 +27,21 @@
|
||||||
namespace absl {
|
namespace absl {
|
||||||
|
|
||||||
AlphaNum::AlphaNum(Hex hex) {
|
AlphaNum::AlphaNum(Hex hex) {
|
||||||
|
static_assert(numbers_internal::kFastToBufferSize >= 32,
|
||||||
|
"This function only works when output buffer >= 32 bytes long");
|
||||||
char* const end = &digits_[numbers_internal::kFastToBufferSize];
|
char* const end = &digits_[numbers_internal::kFastToBufferSize];
|
||||||
char* writer = end;
|
auto real_width =
|
||||||
uint64_t value = hex.value;
|
absl::numbers_internal::FastHexToBufferZeroPad16(hex.value, end - 16);
|
||||||
do {
|
if (real_width >= hex.width) {
|
||||||
*--writer = absl::numbers_internal::kHexChar[value & 0xF];
|
piece_ = absl::string_view(end - real_width, real_width);
|
||||||
value >>= 4;
|
|
||||||
} while (value != 0);
|
|
||||||
|
|
||||||
char* beg;
|
|
||||||
if (end - writer < hex.width) {
|
|
||||||
beg = end - hex.width;
|
|
||||||
std::fill_n(beg, writer - beg, hex.fill);
|
|
||||||
} else {
|
} else {
|
||||||
beg = writer;
|
// Pad first 16 chars because FastHexToBufferZeroPad16 pads only to 16 and
|
||||||
|
// max pad width can be up to 20.
|
||||||
|
std::memset(end - 32, hex.fill, 16);
|
||||||
|
// Patch up everything else up to the real_width.
|
||||||
|
std::memset(end - real_width - 16, hex.fill, 16);
|
||||||
|
piece_ = absl::string_view(end - hex.width, hex.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
piece_ = absl::string_view(beg, end - beg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AlphaNum::AlphaNum(Dec dec) {
|
AlphaNum::AlphaNum(Dec dec) {
|
||||||
|
|
|
@ -400,6 +400,12 @@ int FPrintF(std::FILE* output, const FormatSpec<Args...>& format,
|
||||||
// This function is functionally equivalent to `std::snprintf()` (and
|
// This function is functionally equivalent to `std::snprintf()` (and
|
||||||
// type-safe); prefer `absl::SNPrintF()` over `std::snprintf()`.
|
// type-safe); prefer `absl::SNPrintF()` over `std::snprintf()`.
|
||||||
//
|
//
|
||||||
|
// In particular, a successful call to `absl::SNPrintF()` writes at most `size`
|
||||||
|
// bytes of the formatted output to `output`, including a null terminator, and
|
||||||
|
// returns the number of bytes that would have been written if truncation did
|
||||||
|
// not occur. In the event of an error, a negative value is returned and `errno`
|
||||||
|
// is set.
|
||||||
|
//
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
// std::string_view s = "Ulaanbaatar";
|
// std::string_view s = "Ulaanbaatar";
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#include "absl/strings/string_view.h"
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
#ifndef ABSL_HAVE_STD_STRING_VIEW
|
#ifndef ABSL_USES_STD_STRING_VIEW
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
@ -230,4 +230,4 @@ constexpr string_view::size_type string_view::kMaxSize;
|
||||||
|
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_STRING_VIEW
|
#endif // ABSL_USES_STD_STRING_VIEW
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "absl/base/config.h"
|
#include "absl/base/config.h"
|
||||||
|
|
||||||
#ifdef ABSL_HAVE_STD_STRING_VIEW
|
#ifdef ABSL_USES_STD_STRING_VIEW
|
||||||
|
|
||||||
#include <string_view> // IWYU pragma: export
|
#include <string_view> // IWYU pragma: export
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ namespace absl {
|
||||||
using std::string_view;
|
using std::string_view;
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#else // ABSL_HAVE_STD_STRING_VIEW
|
#else // ABSL_USES_STD_STRING_VIEW
|
||||||
|
|
||||||
#if ABSL_HAVE_BUILTIN(__builtin_memcmp) || \
|
#if ABSL_HAVE_BUILTIN(__builtin_memcmp) || \
|
||||||
(defined(__GNUC__) && !defined(__clang__))
|
(defined(__GNUC__) && !defined(__clang__))
|
||||||
|
@ -580,7 +580,7 @@ std::ostream& operator<<(std::ostream& o, string_view piece);
|
||||||
|
|
||||||
#undef ABSL_INTERNAL_STRING_VIEW_MEMCMP
|
#undef ABSL_INTERNAL_STRING_VIEW_MEMCMP
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_STRING_VIEW
|
#endif // ABSL_USES_STD_STRING_VIEW
|
||||||
|
|
||||||
namespace absl {
|
namespace absl {
|
||||||
|
|
||||||
|
|
|
@ -830,7 +830,7 @@ TEST(StringViewTest, FrontBackSingleChar) {
|
||||||
// to the standard, but `absl::string_view` implements a different
|
// to the standard, but `absl::string_view` implements a different
|
||||||
// behavior for historical reasons. We work around tests that construct
|
// behavior for historical reasons. We work around tests that construct
|
||||||
// `string_view` from `nullptr` when using libc++.
|
// `string_view` from `nullptr` when using libc++.
|
||||||
#if !defined(ABSL_HAVE_STD_STRING_VIEW) || \
|
#if !defined(ABSL_USES_STD_STRING_VIEW) || \
|
||||||
(!(defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 9) && \
|
(!(defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 9) && \
|
||||||
!defined(_LIBCPP_VERSION) && !defined(_MSC_VER))
|
!defined(_LIBCPP_VERSION) && !defined(_MSC_VER))
|
||||||
#define ABSL_HAVE_STRING_VIEW_FROM_NULLPTR 1
|
#define ABSL_HAVE_STRING_VIEW_FROM_NULLPTR 1
|
||||||
|
@ -938,7 +938,7 @@ TEST(StringViewTest, ConstexprCompiles) {
|
||||||
#endif
|
#endif
|
||||||
constexpr absl::string_view cstr_len("cstr", 4);
|
constexpr absl::string_view cstr_len("cstr", 4);
|
||||||
|
|
||||||
#if defined(ABSL_HAVE_STD_STRING_VIEW)
|
#if defined(ABSL_USES_STD_STRING_VIEW)
|
||||||
// In libstdc++ (as of 7.2), `std::string_view::string_view(const char*)`
|
// In libstdc++ (as of 7.2), `std::string_view::string_view(const char*)`
|
||||||
// calls `std::char_traits<char>::length(const char*)` to get the std::string
|
// calls `std::char_traits<char>::length(const char*)` to get the std::string
|
||||||
// length, but it is not marked constexpr yet. See GCC bug:
|
// length, but it is not marked constexpr yet. See GCC bug:
|
||||||
|
@ -952,7 +952,7 @@ TEST(StringViewTest, ConstexprCompiles) {
|
||||||
#define ABSL_HAVE_CONSTEXPR_STRING_VIEW_FROM_CSTR 1
|
#define ABSL_HAVE_CONSTEXPR_STRING_VIEW_FROM_CSTR 1
|
||||||
#endif // !__GLIBCXX__
|
#endif // !__GLIBCXX__
|
||||||
|
|
||||||
#else // ABSL_HAVE_STD_STRING_VIEW
|
#else // ABSL_USES_STD_STRING_VIEW
|
||||||
|
|
||||||
// This duplicates the check for __builtin_strlen in the header.
|
// This duplicates the check for __builtin_strlen in the header.
|
||||||
#if ABSL_HAVE_BUILTIN(__builtin_strlen) || \
|
#if ABSL_HAVE_BUILTIN(__builtin_strlen) || \
|
||||||
|
@ -967,7 +967,7 @@ TEST(StringViewTest, ConstexprCompiles) {
|
||||||
#define ABSL_HAVE_CONSTEXPR_STRING_VIEW_FROM_CSTR 1
|
#define ABSL_HAVE_CONSTEXPR_STRING_VIEW_FROM_CSTR 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_STRING_VIEW
|
#endif // ABSL_USES_STD_STRING_VIEW
|
||||||
|
|
||||||
#ifdef ABSL_HAVE_CONSTEXPR_STRING_VIEW_FROM_CSTR
|
#ifdef ABSL_HAVE_CONSTEXPR_STRING_VIEW_FROM_CSTR
|
||||||
constexpr absl::string_view cstr_strlen("foo");
|
constexpr absl::string_view cstr_strlen("foo");
|
||||||
|
@ -1136,7 +1136,7 @@ TEST(HugeStringView, TwoPointTwoGB) {
|
||||||
}
|
}
|
||||||
#endif // THREAD_SANITIZER
|
#endif // THREAD_SANITIZER
|
||||||
|
|
||||||
#if !defined(NDEBUG) && !defined(ABSL_HAVE_STD_STRING_VIEW)
|
#if !defined(NDEBUG) && !defined(ABSL_USES_STD_STRING_VIEW)
|
||||||
TEST(NonNegativeLenTest, NonNegativeLen) {
|
TEST(NonNegativeLenTest, NonNegativeLen) {
|
||||||
ABSL_EXPECT_DEATH_IF_SUPPORTED(absl::string_view("xyz", -1),
|
ABSL_EXPECT_DEATH_IF_SUPPORTED(absl::string_view("xyz", -1),
|
||||||
"len <= kMaxSize");
|
"len <= kMaxSize");
|
||||||
|
@ -1152,7 +1152,7 @@ TEST(LenExceedsMaxSizeTest, LenExceedsMaxSize) {
|
||||||
ABSL_EXPECT_DEATH_IF_SUPPORTED(absl::string_view("", max_size + 1),
|
ABSL_EXPECT_DEATH_IF_SUPPORTED(absl::string_view("", max_size + 1),
|
||||||
"len <= kMaxSize");
|
"len <= kMaxSize");
|
||||||
}
|
}
|
||||||
#endif // !defined(NDEBUG) && !defined(ABSL_HAVE_STD_STRING_VIEW)
|
#endif // !defined(NDEBUG) && !defined(ABSL_USES_STD_STRING_VIEW)
|
||||||
|
|
||||||
class StringViewStreamTest : public ::testing::Test {
|
class StringViewStreamTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -161,7 +161,7 @@ bool Waiter::Wait(KernelTimeout t) {
|
||||||
|
|
||||||
void Waiter::Post() {
|
void Waiter::Post() {
|
||||||
if (futex_.fetch_add(1, std::memory_order_release) == 0) {
|
if (futex_.fetch_add(1, std::memory_order_release) == 0) {
|
||||||
// We incremented from 0, need to wake a potential waker.
|
// We incremented from 0, need to wake a potential waiter.
|
||||||
Poke();
|
Poke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,8 +210,8 @@ void Waiter::Init() {
|
||||||
ABSL_RAW_LOG(FATAL, "pthread_cond_init failed: %d", err2);
|
ABSL_RAW_LOG(FATAL, "pthread_cond_init failed: %d", err2);
|
||||||
}
|
}
|
||||||
|
|
||||||
waiter_count_.store(0, std::memory_order_relaxed);
|
waiter_count_ = 0;
|
||||||
wakeup_count_.store(0, std::memory_order_relaxed);
|
wakeup_count_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Waiter::Wait(KernelTimeout t) {
|
bool Waiter::Wait(KernelTimeout t) {
|
||||||
|
@ -221,24 +221,12 @@ bool Waiter::Wait(KernelTimeout t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PthreadMutexHolder h(&mu_);
|
PthreadMutexHolder h(&mu_);
|
||||||
waiter_count_.fetch_add(1, std::memory_order_relaxed);
|
++waiter_count_;
|
||||||
// Loop until we find a wakeup to consume or timeout.
|
// Loop until we find a wakeup to consume or timeout.
|
||||||
// Note that, since the thread ticker is just reset, we don't need to check
|
// Note that, since the thread ticker is just reset, we don't need to check
|
||||||
// whether the thread is idle on the very first pass of the loop.
|
// whether the thread is idle on the very first pass of the loop.
|
||||||
bool first_pass = true;
|
bool first_pass = true;
|
||||||
while (true) {
|
while (wakeup_count_ == 0) {
|
||||||
int x = wakeup_count_.load(std::memory_order_relaxed);
|
|
||||||
if (x != 0) {
|
|
||||||
if (!wakeup_count_.compare_exchange_weak(x, x - 1,
|
|
||||||
std::memory_order_acquire,
|
|
||||||
std::memory_order_relaxed)) {
|
|
||||||
continue; // Raced with someone, retry.
|
|
||||||
}
|
|
||||||
// Successfully consumed a wakeup, we're done.
|
|
||||||
waiter_count_.fetch_sub(1, std::memory_order_relaxed);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!first_pass) MaybeBecomeIdle();
|
if (!first_pass) MaybeBecomeIdle();
|
||||||
// No wakeups available, time to wait.
|
// No wakeups available, time to wait.
|
||||||
if (!t.has_timeout()) {
|
if (!t.has_timeout()) {
|
||||||
|
@ -249,35 +237,39 @@ bool Waiter::Wait(KernelTimeout t) {
|
||||||
} else {
|
} else {
|
||||||
const int err = pthread_cond_timedwait(&cv_, &mu_, &abs_timeout);
|
const int err = pthread_cond_timedwait(&cv_, &mu_, &abs_timeout);
|
||||||
if (err == ETIMEDOUT) {
|
if (err == ETIMEDOUT) {
|
||||||
waiter_count_.fetch_sub(1, std::memory_order_relaxed);
|
--waiter_count_;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
ABSL_RAW_LOG(FATAL, "pthread_cond_wait failed: %d", err);
|
ABSL_RAW_LOG(FATAL, "pthread_cond_timedwait failed: %d", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
first_pass = false;
|
first_pass = false;
|
||||||
}
|
}
|
||||||
|
// Consume a wakeup and we're done.
|
||||||
|
--wakeup_count_;
|
||||||
|
--waiter_count_;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Waiter::Post() {
|
void Waiter::Post() {
|
||||||
wakeup_count_.fetch_add(1, std::memory_order_release);
|
PthreadMutexHolder h(&mu_);
|
||||||
Poke();
|
++wakeup_count_;
|
||||||
|
InternalCondVarPoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Waiter::Poke() {
|
void Waiter::Poke() {
|
||||||
if (waiter_count_.load(std::memory_order_relaxed) == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Potentially a waker. Take the lock and check again.
|
|
||||||
PthreadMutexHolder h(&mu_);
|
PthreadMutexHolder h(&mu_);
|
||||||
if (waiter_count_.load(std::memory_order_relaxed) == 0) {
|
InternalCondVarPoke();
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
void Waiter::InternalCondVarPoke() {
|
||||||
|
if (waiter_count_ != 0) {
|
||||||
const int err = pthread_cond_signal(&cv_);
|
const int err = pthread_cond_signal(&cv_);
|
||||||
if (err != 0) {
|
if (ABSL_PREDICT_FALSE(err != 0)) {
|
||||||
ABSL_RAW_LOG(FATAL, "pthread_cond_signal failed: %d", err);
|
ABSL_RAW_LOG(FATAL, "pthread_cond_signal failed: %d", err);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_SEM
|
#elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_SEM
|
||||||
|
@ -456,7 +448,7 @@ void Waiter::Poke() {
|
||||||
if (waiter_count_.load(std::memory_order_relaxed) == 0) {
|
if (waiter_count_.load(std::memory_order_relaxed) == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Potentially a waker. Take the lock and check again.
|
// Potentially a waiter. Take the lock and check again.
|
||||||
LockHolder h(WinHelper::GetLock(this));
|
LockHolder h(WinHelper::GetLock(this));
|
||||||
if (waiter_count_.load(std::memory_order_relaxed) == 0) {
|
if (waiter_count_.load(std::memory_order_relaxed) == 0) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -106,10 +106,13 @@ class Waiter {
|
||||||
static_assert(sizeof(int32_t) == sizeof(futex_), "Wrong size for futex");
|
static_assert(sizeof(int32_t) == sizeof(futex_), "Wrong size for futex");
|
||||||
|
|
||||||
#elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_CONDVAR
|
#elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_CONDVAR
|
||||||
|
// REQUIRES: mu_ must be held.
|
||||||
|
void InternalCondVarPoke();
|
||||||
|
|
||||||
pthread_mutex_t mu_;
|
pthread_mutex_t mu_;
|
||||||
pthread_cond_t cv_;
|
pthread_cond_t cv_;
|
||||||
std::atomic<int> waiter_count_;
|
int waiter_count_;
|
||||||
std::atomic<int> wakeup_count_; // Unclaimed wakeups, written under lock.
|
int wakeup_count_; // Unclaimed wakeups.
|
||||||
|
|
||||||
#elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_SEM
|
#elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_SEM
|
||||||
sem_t sem_;
|
sem_t sem_;
|
||||||
|
|
|
@ -122,6 +122,11 @@ class OnDestruction {
|
||||||
Function fn_;
|
Function fn_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// These tests require that the compiler correctly supports C++11 constant
|
||||||
|
// initialization... but MSVC has a known regression since v19.10:
|
||||||
|
// https://developercommunity.visualstudio.com/content/problem/336946/class-with-constexpr-constructor-not-using-static.html
|
||||||
|
// TODO(epastor): Limit the affected range once MSVC fixes this bug.
|
||||||
|
#if defined(__clang__) || !(defined(_MSC_VER) && _MSC_VER > 1900)
|
||||||
// kConstInit
|
// kConstInit
|
||||||
// Test early usage. (Declaration comes first; definitions must appear after
|
// Test early usage. (Declaration comes first; definitions must appear after
|
||||||
// the test runner.)
|
// the test runner.)
|
||||||
|
@ -151,6 +156,7 @@ OnConstruction check_still_locked([]() ABSL_NO_THREAD_SAFETY_ANALYSIS {
|
||||||
const_init_sanity_mutex.AssertHeld();
|
const_init_sanity_mutex.AssertHeld();
|
||||||
const_init_sanity_mutex.Unlock();
|
const_init_sanity_mutex.Unlock();
|
||||||
});
|
});
|
||||||
|
#endif // defined(__clang__) || !(defined(_MSC_VER) && _MSC_VER > 1900)
|
||||||
|
|
||||||
// Test shutdown usage. (Declarations come first; definitions must appear after
|
// Test shutdown usage. (Declarations come first; definitions must appear after
|
||||||
// the test runner.)
|
// the test runner.)
|
||||||
|
|
|
@ -519,7 +519,7 @@ namespace time_internal { // For functions found via ADL on civil-time tags.
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
// absl::CivilDay d = absl::CivilDay("1969-07-20");
|
// absl::CivilDay d = absl::CivilDay(1969, 7, 20);
|
||||||
// std::cout << "Date is: " << d << "\n";
|
// std::cout << "Date is: " << d << "\n";
|
||||||
//
|
//
|
||||||
std::ostream& operator<<(std::ostream& os, CivilYear y);
|
std::ostream& operator<<(std::ostream& os, CivilYear y);
|
||||||
|
|
|
@ -197,11 +197,11 @@ inline int64_t DecodeTwosComp(uint64_t v) { return absl::bit_cast<int64_t>(v); }
|
||||||
// double as overflow cases.
|
// double as overflow cases.
|
||||||
inline bool SafeAddRepHi(double a_hi, double b_hi, Duration* d) {
|
inline bool SafeAddRepHi(double a_hi, double b_hi, Duration* d) {
|
||||||
double c = a_hi + b_hi;
|
double c = a_hi + b_hi;
|
||||||
if (c >= kint64max) {
|
if (c >= static_cast<double>(kint64max)) {
|
||||||
*d = InfiniteDuration();
|
*d = InfiniteDuration();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (c <= kint64min) {
|
if (c <= static_cast<double>(kint64min)) {
|
||||||
*d = -InfiniteDuration();
|
*d = -InfiniteDuration();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,7 +422,9 @@ Duration Milliseconds(T n) {
|
||||||
template <typename T, time_internal::EnableIfFloat<T> = 0>
|
template <typename T, time_internal::EnableIfFloat<T> = 0>
|
||||||
Duration Seconds(T n) {
|
Duration Seconds(T n) {
|
||||||
if (n >= 0) { // Note: `NaN >= 0` is false.
|
if (n >= 0) { // Note: `NaN >= 0` is false.
|
||||||
if (n >= (std::numeric_limits<int64_t>::max)()) return InfiniteDuration();
|
if (n >= static_cast<T>((std::numeric_limits<int64_t>::max)())) {
|
||||||
|
return InfiniteDuration();
|
||||||
|
}
|
||||||
return time_internal::MakePosDoubleDuration(n);
|
return time_internal::MakePosDoubleDuration(n);
|
||||||
} else {
|
} else {
|
||||||
if (std::isnan(n))
|
if (std::isnan(n))
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
#include "absl/base/config.h"
|
#include "absl/base/config.h"
|
||||||
#include "absl/utility/utility.h"
|
#include "absl/utility/utility.h"
|
||||||
|
|
||||||
#ifdef ABSL_HAVE_STD_ANY
|
#ifdef ABSL_USES_STD_ANY
|
||||||
|
|
||||||
#include <any> // IWYU pragma: export
|
#include <any> // IWYU pragma: export
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ using std::bad_any_cast;
|
||||||
using std::make_any;
|
using std::make_any;
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#else // ABSL_HAVE_STD_ANY
|
#else // ABSL_USES_STD_ANY
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
@ -538,6 +538,6 @@ T* any_cast(any* operand) noexcept {
|
||||||
|
|
||||||
#undef ABSL_ANY_DETAIL_HAS_RTTI
|
#undef ABSL_ANY_DETAIL_HAS_RTTI
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_ANY
|
#endif // ABSL_USES_STD_ANY
|
||||||
|
|
||||||
#endif // ABSL_TYPES_ANY_H_
|
#endif // ABSL_TYPES_ANY_H_
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
// This test is a no-op when absl::any is an alias for std::any and when
|
// This test is a no-op when absl::any is an alias for std::any and when
|
||||||
// exceptions are not enabled.
|
// exceptions are not enabled.
|
||||||
#if !defined(ABSL_HAVE_STD_ANY) && defined(ABSL_HAVE_EXCEPTIONS)
|
#if !defined(ABSL_USES_STD_ANY) && defined(ABSL_HAVE_EXCEPTIONS)
|
||||||
|
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -170,4 +170,4 @@ TEST(AnyExceptionSafety, Emplace) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#endif // #if !defined(ABSL_HAVE_STD_ANY) && defined(ABSL_HAVE_EXCEPTIONS)
|
#endif // #if !defined(ABSL_USES_STD_ANY) && defined(ABSL_HAVE_EXCEPTIONS)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include "absl/types/any.h"
|
#include "absl/types/any.h"
|
||||||
|
|
||||||
// This test is a no-op when absl::any is an alias for std::any.
|
// This test is a no-op when absl::any is an alias for std::any.
|
||||||
#if !defined(ABSL_HAVE_STD_ANY)
|
#if !defined(ABSL_USES_STD_ANY)
|
||||||
|
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
@ -642,7 +642,7 @@ TEST(AnyTest, ConversionConstructionCausesOneCopy) {
|
||||||
// Tests for Exception Behavior //
|
// Tests for Exception Behavior //
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
|
||||||
#if defined(ABSL_HAVE_STD_ANY)
|
#if defined(ABSL_USES_STD_ANY)
|
||||||
|
|
||||||
// If using a std `any` implementation, we can't check for a specific message.
|
// If using a std `any` implementation, we can't check for a specific message.
|
||||||
#define ABSL_ANY_TEST_EXPECT_BAD_ANY_CAST(...) \
|
#define ABSL_ANY_TEST_EXPECT_BAD_ANY_CAST(...) \
|
||||||
|
@ -656,7 +656,7 @@ TEST(AnyTest, ConversionConstructionCausesOneCopy) {
|
||||||
ABSL_BASE_INTERNAL_EXPECT_FAIL((__VA_ARGS__), absl::bad_any_cast, \
|
ABSL_BASE_INTERNAL_EXPECT_FAIL((__VA_ARGS__), absl::bad_any_cast, \
|
||||||
"Bad any cast")
|
"Bad any cast")
|
||||||
|
|
||||||
#endif // defined(ABSL_HAVE_STD_ANY)
|
#endif // defined(ABSL_USES_STD_ANY)
|
||||||
|
|
||||||
TEST(AnyTest, ThrowBadAlloc) {
|
TEST(AnyTest, ThrowBadAlloc) {
|
||||||
{
|
{
|
||||||
|
@ -764,7 +764,7 @@ TEST(AnyTest, FailedEmplace) {
|
||||||
BadCopyable bad;
|
BadCopyable bad;
|
||||||
absl::any target(absl::in_place_type<int>);
|
absl::any target(absl::in_place_type<int>);
|
||||||
ABSL_ANY_TEST_EXPECT_BAD_COPY(target.emplace<BadCopyable>(bad));
|
ABSL_ANY_TEST_EXPECT_BAD_COPY(target.emplace<BadCopyable>(bad));
|
||||||
#if defined(ABSL_HAVE_STD_ANY) && defined(__GLIBCXX__)
|
#if defined(ABSL_USES_STD_ANY) && defined(__GLIBCXX__)
|
||||||
// libstdc++ std::any::emplace() implementation (as of 7.2) has a bug: if an
|
// libstdc++ std::any::emplace() implementation (as of 7.2) has a bug: if an
|
||||||
// exception is thrown, *this contains a value.
|
// exception is thrown, *this contains a value.
|
||||||
#define ABSL_GLIBCXX_ANY_EMPLACE_EXCEPTION_BUG 1
|
#define ABSL_GLIBCXX_ANY_EMPLACE_EXCEPTION_BUG 1
|
||||||
|
@ -778,4 +778,4 @@ TEST(AnyTest, FailedEmplace) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#endif // #if !defined(ABSL_HAVE_STD_ANY)
|
#endif // #if !defined(ABSL_USES_STD_ANY)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#include "absl/types/bad_any_cast.h"
|
#include "absl/types/bad_any_cast.h"
|
||||||
|
|
||||||
#ifndef ABSL_HAVE_STD_ANY
|
#ifndef ABSL_USES_STD_ANY
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
@ -41,4 +41,4 @@ void ThrowBadAnyCast() {
|
||||||
} // namespace any_internal
|
} // namespace any_internal
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_ANY
|
#endif // ABSL_USES_STD_ANY
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#include "absl/base/config.h"
|
#include "absl/base/config.h"
|
||||||
|
|
||||||
#ifdef ABSL_HAVE_STD_ANY
|
#ifdef ABSL_USES_STD_ANY
|
||||||
|
|
||||||
#include <any>
|
#include <any>
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ namespace absl {
|
||||||
using std::bad_any_cast;
|
using std::bad_any_cast;
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#else // ABSL_HAVE_STD_ANY
|
#else // ABSL_USES_STD_ANY
|
||||||
|
|
||||||
namespace absl {
|
namespace absl {
|
||||||
|
|
||||||
|
@ -66,6 +66,6 @@ namespace any_internal {
|
||||||
} // namespace any_internal
|
} // namespace any_internal
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_ANY
|
#endif // ABSL_USES_STD_ANY
|
||||||
|
|
||||||
#endif // ABSL_TYPES_BAD_ANY_CAST_H_
|
#endif // ABSL_TYPES_BAD_ANY_CAST_H_
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#include "absl/types/bad_optional_access.h"
|
#include "absl/types/bad_optional_access.h"
|
||||||
|
|
||||||
#ifndef ABSL_HAVE_STD_OPTIONAL
|
#ifndef ABSL_USES_STD_OPTIONAL
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
@ -43,4 +43,4 @@ void throw_bad_optional_access() {
|
||||||
} // namespace optional_internal
|
} // namespace optional_internal
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_OPTIONAL
|
#endif // ABSL_USES_STD_OPTIONAL
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#include "absl/base/config.h"
|
#include "absl/base/config.h"
|
||||||
|
|
||||||
#ifdef ABSL_HAVE_STD_OPTIONAL
|
#ifdef ABSL_USES_STD_OPTIONAL
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ namespace absl {
|
||||||
using std::bad_optional_access;
|
using std::bad_optional_access;
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#else // ABSL_HAVE_STD_OPTIONAL
|
#else // ABSL_USES_STD_OPTIONAL
|
||||||
|
|
||||||
namespace absl {
|
namespace absl {
|
||||||
|
|
||||||
|
@ -69,6 +69,6 @@ namespace optional_internal {
|
||||||
} // namespace optional_internal
|
} // namespace optional_internal
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_OPTIONAL
|
#endif // ABSL_USES_STD_OPTIONAL
|
||||||
|
|
||||||
#endif // ABSL_TYPES_BAD_OPTIONAL_ACCESS_H_
|
#endif // ABSL_TYPES_BAD_OPTIONAL_ACCESS_H_
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#include "absl/types/bad_variant_access.h"
|
#include "absl/types/bad_variant_access.h"
|
||||||
|
|
||||||
#ifndef ABSL_HAVE_STD_VARIANT
|
#ifndef ABSL_USES_STD_VARIANT
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -59,4 +59,4 @@ void Rethrow() {
|
||||||
} // namespace variant_internal
|
} // namespace variant_internal
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_VARIANT
|
#endif // ABSL_USES_STD_VARIANT
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#include "absl/base/config.h"
|
#include "absl/base/config.h"
|
||||||
|
|
||||||
#ifdef ABSL_HAVE_STD_VARIANT
|
#ifdef ABSL_USES_STD_VARIANT
|
||||||
|
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ namespace absl {
|
||||||
using std::bad_variant_access;
|
using std::bad_variant_access;
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#else // ABSL_HAVE_STD_VARIANT
|
#else // ABSL_USES_STD_VARIANT
|
||||||
|
|
||||||
namespace absl {
|
namespace absl {
|
||||||
|
|
||||||
|
@ -73,6 +73,6 @@ namespace variant_internal {
|
||||||
} // namespace variant_internal
|
} // namespace variant_internal
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_VARIANT
|
#endif // ABSL_USES_STD_VARIANT
|
||||||
|
|
||||||
#endif // ABSL_TYPES_BAD_VARIANT_ACCESS_H_
|
#endif // ABSL_TYPES_BAD_VARIANT_ACCESS_H_
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#include "absl/types/bad_variant_access.h"
|
#include "absl/types/bad_variant_access.h"
|
||||||
#include "absl/utility/utility.h"
|
#include "absl/utility/utility.h"
|
||||||
|
|
||||||
#if !defined(ABSL_HAVE_STD_VARIANT)
|
#if !defined(ABSL_USES_STD_VARIANT)
|
||||||
|
|
||||||
namespace absl {
|
namespace absl {
|
||||||
|
|
||||||
|
@ -1640,5 +1640,5 @@ struct VariantHashBase<Variant,
|
||||||
} // namespace variant_internal
|
} // namespace variant_internal
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // !defined(ABSL_HAVE_STD_VARIANT)
|
#endif // !defined(ABSL_USES_STD_VARIANT)
|
||||||
#endif // ABSL_TYPES_variant_internal_H_
|
#endif // ABSL_TYPES_variant_internal_H_
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "absl/base/config.h" // TODO(calabrese) IWYU removal?
|
#include "absl/base/config.h" // TODO(calabrese) IWYU removal?
|
||||||
#include "absl/utility/utility.h"
|
#include "absl/utility/utility.h"
|
||||||
|
|
||||||
#ifdef ABSL_HAVE_STD_OPTIONAL
|
#ifdef ABSL_USES_STD_OPTIONAL
|
||||||
|
|
||||||
#include <optional> // IWYU pragma: export
|
#include <optional> // IWYU pragma: export
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ using std::nullopt_t;
|
||||||
using std::nullopt;
|
using std::nullopt;
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#else // ABSL_HAVE_STD_OPTIONAL
|
#else // ABSL_USES_STD_OPTIONAL
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -767,6 +767,6 @@ struct hash<absl::optional<T> >
|
||||||
|
|
||||||
#undef ABSL_MSVC_CONSTEXPR_BUG_IN_UNION_LIKE_CLASS
|
#undef ABSL_MSVC_CONSTEXPR_BUG_IN_UNION_LIKE_CLASS
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_OPTIONAL
|
#endif // ABSL_USES_STD_OPTIONAL
|
||||||
|
|
||||||
#endif // ABSL_TYPES_OPTIONAL_H_
|
#endif // ABSL_TYPES_OPTIONAL_H_
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
// This test is a no-op when absl::optional is an alias for std::optional and
|
// This test is a no-op when absl::optional is an alias for std::optional and
|
||||||
// when exceptions are not enabled.
|
// when exceptions are not enabled.
|
||||||
#if !defined(ABSL_HAVE_STD_OPTIONAL) && defined(ABSL_HAVE_EXCEPTIONS)
|
#if !defined(ABSL_USES_STD_OPTIONAL) && defined(ABSL_HAVE_EXCEPTIONS)
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "absl/base/internal/exception_safety_testing.h"
|
#include "absl/base/internal/exception_safety_testing.h"
|
||||||
|
@ -287,4 +287,4 @@ TEST(OptionalExceptionSafety, NothrowMoveAssign) {
|
||||||
|
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // #if !defined(ABSL_HAVE_STD_OPTIONAL) && defined(ABSL_HAVE_EXCEPTIONS)
|
#endif // #if !defined(ABSL_USES_STD_OPTIONAL) && defined(ABSL_HAVE_EXCEPTIONS)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
|
|
||||||
// This test is a no-op when absl::optional is an alias for std::optional.
|
// This test is a no-op when absl::optional is an alias for std::optional.
|
||||||
#if !defined(ABSL_HAVE_STD_OPTIONAL)
|
#if !defined(ABSL_USES_STD_OPTIONAL)
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
@ -224,7 +224,7 @@ TEST(optionalTest, CopyConstructor) {
|
||||||
|
|
||||||
EXPECT_FALSE(
|
EXPECT_FALSE(
|
||||||
absl::is_trivially_copy_constructible<absl::optional<Copyable>>::value);
|
absl::is_trivially_copy_constructible<absl::optional<Copyable>>::value);
|
||||||
#if defined(ABSL_HAVE_STD_OPTIONAL) && defined(__GLIBCXX__)
|
#if defined(ABSL_USES_STD_OPTIONAL) && defined(__GLIBCXX__)
|
||||||
// libstdc++ std::optional implementation (as of 7.2) has a bug: when T is
|
// libstdc++ std::optional implementation (as of 7.2) has a bug: when T is
|
||||||
// trivially copyable, optional<T> is not trivially copyable (due to one of
|
// trivially copyable, optional<T> is not trivially copyable (due to one of
|
||||||
// its base class is unconditionally nontrivial).
|
// its base class is unconditionally nontrivial).
|
||||||
|
@ -279,7 +279,7 @@ TEST(optionalTest, CopyConstructor) {
|
||||||
// std::optional when T is volatile-qualified. So skipping this test.
|
// std::optional when T is volatile-qualified. So skipping this test.
|
||||||
// Bug report:
|
// Bug report:
|
||||||
// https://connect.microsoft.com/VisualStudio/feedback/details/3142534
|
// https://connect.microsoft.com/VisualStudio/feedback/details/3142534
|
||||||
#if defined(ABSL_HAVE_STD_OPTIONAL) && defined(_MSC_VER) && _MSC_VER >= 1911
|
#if defined(ABSL_USES_STD_OPTIONAL) && defined(_MSC_VER) && _MSC_VER >= 1911
|
||||||
#define ABSL_MSVC_OPTIONAL_VOLATILE_COPY_BUG 1
|
#define ABSL_MSVC_OPTIONAL_VOLATILE_COPY_BUG 1
|
||||||
#endif
|
#endif
|
||||||
#ifndef ABSL_MSVC_OPTIONAL_VOLATILE_COPY_BUG
|
#ifndef ABSL_MSVC_OPTIONAL_VOLATILE_COPY_BUG
|
||||||
|
@ -305,7 +305,7 @@ TEST(optionalTest, MoveConstructor) {
|
||||||
EXPECT_FALSE(std::is_move_constructible<absl::optional<NonMovable>>::value);
|
EXPECT_FALSE(std::is_move_constructible<absl::optional<NonMovable>>::value);
|
||||||
// test noexcept
|
// test noexcept
|
||||||
EXPECT_TRUE(std::is_nothrow_move_constructible<absl::optional<int>>::value);
|
EXPECT_TRUE(std::is_nothrow_move_constructible<absl::optional<int>>::value);
|
||||||
#ifndef ABSL_HAVE_STD_OPTIONAL
|
#ifndef ABSL_USES_STD_OPTIONAL
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
absl::default_allocator_is_nothrow::value,
|
absl::default_allocator_is_nothrow::value,
|
||||||
std::is_nothrow_move_constructible<absl::optional<MoveableThrow>>::value);
|
std::is_nothrow_move_constructible<absl::optional<MoveableThrow>>::value);
|
||||||
|
@ -639,7 +639,7 @@ TEST(optionalTest, CopyAssignment) {
|
||||||
EXPECT_FALSE(absl::is_trivially_copy_assignable<NonTrivial>::value);
|
EXPECT_FALSE(absl::is_trivially_copy_assignable<NonTrivial>::value);
|
||||||
|
|
||||||
// std::optional doesn't support volatile nontrivial types.
|
// std::optional doesn't support volatile nontrivial types.
|
||||||
#ifndef ABSL_HAVE_STD_OPTIONAL
|
#ifndef ABSL_USES_STD_OPTIONAL
|
||||||
{
|
{
|
||||||
StructorListener listener;
|
StructorListener listener;
|
||||||
Listenable::listener = &listener;
|
Listenable::listener = &listener;
|
||||||
|
@ -658,7 +658,7 @@ TEST(optionalTest, CopyAssignment) {
|
||||||
EXPECT_EQ(1, listener.destruct);
|
EXPECT_EQ(1, listener.destruct);
|
||||||
EXPECT_EQ(1, listener.volatile_copy_assign);
|
EXPECT_EQ(1, listener.volatile_copy_assign);
|
||||||
}
|
}
|
||||||
#endif // ABSL_HAVE_STD_OPTIONAL
|
#endif // ABSL_USES_STD_OPTIONAL
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(optionalTest, MoveAssignment) {
|
TEST(optionalTest, MoveAssignment) {
|
||||||
|
@ -682,7 +682,7 @@ TEST(optionalTest, MoveAssignment) {
|
||||||
EXPECT_EQ(1, listener.move_assign);
|
EXPECT_EQ(1, listener.move_assign);
|
||||||
}
|
}
|
||||||
// std::optional doesn't support volatile nontrivial types.
|
// std::optional doesn't support volatile nontrivial types.
|
||||||
#ifndef ABSL_HAVE_STD_OPTIONAL
|
#ifndef ABSL_USES_STD_OPTIONAL
|
||||||
{
|
{
|
||||||
StructorListener listener;
|
StructorListener listener;
|
||||||
Listenable::listener = &listener;
|
Listenable::listener = &listener;
|
||||||
|
@ -702,7 +702,7 @@ TEST(optionalTest, MoveAssignment) {
|
||||||
EXPECT_EQ(1, listener.destruct);
|
EXPECT_EQ(1, listener.destruct);
|
||||||
EXPECT_EQ(1, listener.volatile_move_assign);
|
EXPECT_EQ(1, listener.volatile_move_assign);
|
||||||
}
|
}
|
||||||
#endif // ABSL_HAVE_STD_OPTIONAL
|
#endif // ABSL_USES_STD_OPTIONAL
|
||||||
EXPECT_FALSE(absl::is_move_assignable<absl::optional<const int>>::value);
|
EXPECT_FALSE(absl::is_move_assignable<absl::optional<const int>>::value);
|
||||||
EXPECT_TRUE(absl::is_move_assignable<absl::optional<Copyable>>::value);
|
EXPECT_TRUE(absl::is_move_assignable<absl::optional<Copyable>>::value);
|
||||||
EXPECT_TRUE(absl::is_move_assignable<absl::optional<MoveableThrow>>::value);
|
EXPECT_TRUE(absl::is_move_assignable<absl::optional<MoveableThrow>>::value);
|
||||||
|
@ -1560,7 +1560,7 @@ TEST(optionalTest, NoExcept) {
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_nothrow_move_constructible<absl::optional<MoveMeNoThrow>>::value,
|
std::is_nothrow_move_constructible<absl::optional<MoveMeNoThrow>>::value,
|
||||||
"");
|
"");
|
||||||
#ifndef ABSL_HAVE_STD_OPTIONAL
|
#ifndef ABSL_USES_STD_OPTIONAL
|
||||||
static_assert(absl::default_allocator_is_nothrow::value ==
|
static_assert(absl::default_allocator_is_nothrow::value ==
|
||||||
std::is_nothrow_move_constructible<
|
std::is_nothrow_move_constructible<
|
||||||
absl::optional<MoveMeThrow>>::value,
|
absl::optional<MoveMeThrow>>::value,
|
||||||
|
@ -1658,4 +1658,4 @@ TEST(optionalTest, InPlaceTSFINAEBug) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#endif // #if !defined(ABSL_HAVE_STD_OPTIONAL)
|
#endif // #if !defined(ABSL_USES_STD_OPTIONAL)
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
#include "absl/base/config.h"
|
#include "absl/base/config.h"
|
||||||
#include "absl/utility/utility.h"
|
#include "absl/utility/utility.h"
|
||||||
|
|
||||||
#ifdef ABSL_HAVE_STD_VARIANT
|
#ifdef ABSL_USES_STD_VARIANT
|
||||||
|
|
||||||
#include <variant> // IWYU pragma: export
|
#include <variant> // IWYU pragma: export
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ using std::variant_size_v;
|
||||||
using std::visit;
|
using std::visit;
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#else // ABSL_HAVE_STD_VARIANT
|
#else // ABSL_USES_STD_VARIANT
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
@ -812,7 +812,7 @@ struct hash<absl::variant<T...>>
|
||||||
|
|
||||||
} // namespace std
|
} // namespace std
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_VARIANT
|
#endif // ABSL_USES_STD_VARIANT
|
||||||
|
|
||||||
namespace absl {
|
namespace absl {
|
||||||
namespace variant_internal {
|
namespace variant_internal {
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
// This test is a no-op when absl::variant is an alias for std::variant and when
|
// This test is a no-op when absl::variant is an alias for std::variant and when
|
||||||
// exceptions are not enabled.
|
// exceptions are not enabled.
|
||||||
#if !defined(ABSL_HAVE_STD_VARIANT) && defined(ABSL_HAVE_EXCEPTIONS)
|
#if !defined(ABSL_USES_STD_VARIANT) && defined(ABSL_HAVE_EXCEPTIONS)
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -237,7 +237,7 @@ TEST(VariantExceptionSafetyTest, CopyAssign) {
|
||||||
}
|
}
|
||||||
// libstdc++ std::variant has bugs on copy assignment regarding exception
|
// libstdc++ std::variant has bugs on copy assignment regarding exception
|
||||||
// safety.
|
// safety.
|
||||||
#if !(defined(ABSL_HAVE_STD_VARIANT) && defined(__GLIBCXX__))
|
#if !(defined(ABSL_USES_STD_VARIANT) && defined(__GLIBCXX__))
|
||||||
// index() != j
|
// index() != j
|
||||||
// if is_nothrow_copy_constructible_v<Tj> or
|
// if is_nothrow_copy_constructible_v<Tj> or
|
||||||
// !is_nothrow_move_constructible<Tj> is true, equivalent to
|
// !is_nothrow_move_constructible<Tj> is true, equivalent to
|
||||||
|
@ -268,7 +268,7 @@ TEST(VariantExceptionSafetyTest, CopyAssign) {
|
||||||
.Test());
|
.Test());
|
||||||
EXPECT_FALSE(tester.WithContracts(strong_guarantee).Test());
|
EXPECT_FALSE(tester.WithContracts(strong_guarantee).Test());
|
||||||
}
|
}
|
||||||
#endif // !(defined(ABSL_HAVE_STD_VARIANT) && defined(__GLIBCXX__))
|
#endif // !(defined(ABSL_USES_STD_VARIANT) && defined(__GLIBCXX__))
|
||||||
{
|
{
|
||||||
// is_nothrow_copy_constructible_v<Tj> == false &&
|
// is_nothrow_copy_constructible_v<Tj> == false &&
|
||||||
// is_nothrow_move_constructible_v<Tj> == true
|
// is_nothrow_move_constructible_v<Tj> == true
|
||||||
|
@ -325,7 +325,7 @@ TEST(VariantExceptionSafetyTest, MoveAssign) {
|
||||||
// The fix is targeted for gcc-9.
|
// The fix is targeted for gcc-9.
|
||||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87431#c7
|
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87431#c7
|
||||||
// https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=267614
|
// https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=267614
|
||||||
#if !(defined(ABSL_HAVE_STD_VARIANT) && \
|
#if !(defined(ABSL_USES_STD_VARIANT) && \
|
||||||
defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE == 8)
|
defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE == 8)
|
||||||
// - otherwise (index() != j), equivalent to
|
// - otherwise (index() != j), equivalent to
|
||||||
// emplace<j>(get<j>(std::move(rhs)))
|
// emplace<j>(get<j>(std::move(rhs)))
|
||||||
|
@ -342,7 +342,7 @@ TEST(VariantExceptionSafetyTest, MoveAssign) {
|
||||||
auto copy = rhs;
|
auto copy = rhs;
|
||||||
*lhs = std::move(copy);
|
*lhs = std::move(copy);
|
||||||
}));
|
}));
|
||||||
#endif // !(defined(ABSL_HAVE_STD_VARIANT) &&
|
#endif // !(defined(ABSL_USES_STD_VARIANT) &&
|
||||||
// defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE == 8)
|
// defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE == 8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -445,7 +445,7 @@ TEST(VariantExceptionSafetyTest, ValueAssign) {
|
||||||
// and operator=(variant&&) invokes Tj's move ctor which doesn't throw.
|
// and operator=(variant&&) invokes Tj's move ctor which doesn't throw.
|
||||||
// libstdc++ std::variant has bugs on conversion assignment regarding
|
// libstdc++ std::variant has bugs on conversion assignment regarding
|
||||||
// exception safety.
|
// exception safety.
|
||||||
#if !(defined(ABSL_HAVE_STD_VARIANT) && defined(__GLIBCXX__))
|
#if !(defined(ABSL_USES_STD_VARIANT) && defined(__GLIBCXX__))
|
||||||
{
|
{
|
||||||
MoveNothrow rhs;
|
MoveNothrow rhs;
|
||||||
EXPECT_TRUE(MakeExceptionSafetyTester()
|
EXPECT_TRUE(MakeExceptionSafetyTester()
|
||||||
|
@ -453,7 +453,7 @@ TEST(VariantExceptionSafetyTest, ValueAssign) {
|
||||||
.WithContracts(VariantInvariants, strong_guarantee)
|
.WithContracts(VariantInvariants, strong_guarantee)
|
||||||
.Test([&rhs](ThrowingVariant* lhs) { *lhs = rhs; }));
|
.Test([&rhs](ThrowingVariant* lhs) { *lhs = rhs; }));
|
||||||
}
|
}
|
||||||
#endif // !(defined(ABSL_HAVE_STD_VARIANT) && defined(__GLIBCXX__))
|
#endif // !(defined(ABSL_USES_STD_VARIANT) && defined(__GLIBCXX__))
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(VariantExceptionSafetyTest, Emplace) {
|
TEST(VariantExceptionSafetyTest, Emplace) {
|
||||||
|
@ -527,4 +527,4 @@ TEST(VariantExceptionSafetyTest, Swap) {
|
||||||
|
|
||||||
#endif // !defined(ABSL_INTERNAL_MSVC_2017_DBG_MODE)
|
#endif // !defined(ABSL_INTERNAL_MSVC_2017_DBG_MODE)
|
||||||
|
|
||||||
#endif // #if !defined(ABSL_HAVE_STD_VARIANT) && defined(ABSL_HAVE_EXCEPTIONS)
|
#endif // #if !defined(ABSL_USES_STD_VARIANT) && defined(ABSL_HAVE_EXCEPTIONS)
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "absl/types/variant.h"
|
#include "absl/types/variant.h"
|
||||||
|
|
||||||
// This test is a no-op when absl::variant is an alias for std::variant.
|
// This test is a no-op when absl::variant is an alias for std::variant.
|
||||||
#if !defined(ABSL_HAVE_STD_VARIANT)
|
#if !defined(ABSL_USES_STD_VARIANT)
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
@ -842,7 +842,7 @@ TEST(VariantTest, TestBackupAssign) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// libstdc++ doesn't pass this test
|
// libstdc++ doesn't pass this test
|
||||||
#if !(defined(ABSL_HAVE_STD_VARIANT) && defined(__GLIBCXX__))
|
#if !(defined(ABSL_USES_STD_VARIANT) && defined(__GLIBCXX__))
|
||||||
EXPECT_EQ(3, counter[0]);
|
EXPECT_EQ(3, counter[0]);
|
||||||
EXPECT_EQ(2, counter[1]);
|
EXPECT_EQ(2, counter[1]);
|
||||||
EXPECT_EQ(2, counter[2]);
|
EXPECT_EQ(2, counter[2]);
|
||||||
|
@ -1933,7 +1933,7 @@ TEST(VariantTest, VisitReferenceWrapper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// libstdc++ std::variant doesn't support the INVOKE semantics.
|
// libstdc++ std::variant doesn't support the INVOKE semantics.
|
||||||
#if !(defined(ABSL_HAVE_STD_VARIANT) && defined(__GLIBCXX__))
|
#if !(defined(ABSL_USES_STD_VARIANT) && defined(__GLIBCXX__))
|
||||||
TEST(VariantTest, VisitMemberFunction) {
|
TEST(VariantTest, VisitMemberFunction) {
|
||||||
absl::variant<std::unique_ptr<Class>> p(absl::make_unique<Class>());
|
absl::variant<std::unique_ptr<Class>> p(absl::make_unique<Class>());
|
||||||
absl::variant<std::unique_ptr<const Class>> cp(
|
absl::variant<std::unique_ptr<const Class>> cp(
|
||||||
|
@ -1957,7 +1957,7 @@ TEST(VariantTest, VisitDataMember) {
|
||||||
|
|
||||||
EXPECT_EQ(42, absl::visit(&Class::member, cp));
|
EXPECT_EQ(42, absl::visit(&Class::member, cp));
|
||||||
}
|
}
|
||||||
#endif // !(defined(ABSL_HAVE_STD_VARIANT) && defined(__GLIBCXX__))
|
#endif // !(defined(ABSL_USES_STD_VARIANT) && defined(__GLIBCXX__))
|
||||||
|
|
||||||
/////////////////////////
|
/////////////////////////
|
||||||
// [variant.monostate] //
|
// [variant.monostate] //
|
||||||
|
@ -2035,7 +2035,7 @@ TEST(VariantTest, NonmemberSwap) {
|
||||||
std::swap(a, b);
|
std::swap(a, b);
|
||||||
EXPECT_THAT(a, VariantWith<SpecialSwap>(v2));
|
EXPECT_THAT(a, VariantWith<SpecialSwap>(v2));
|
||||||
EXPECT_THAT(b, VariantWith<SpecialSwap>(v1));
|
EXPECT_THAT(b, VariantWith<SpecialSwap>(v1));
|
||||||
#ifndef ABSL_HAVE_STD_VARIANT
|
#ifndef ABSL_USES_STD_VARIANT
|
||||||
EXPECT_FALSE(absl::get<SpecialSwap>(a).special_swap);
|
EXPECT_FALSE(absl::get<SpecialSwap>(a).special_swap);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2083,7 +2083,7 @@ TEST(VariantTest, Hash) {
|
||||||
|
|
||||||
// MSVC std::hash<std::variant> does not use the index, thus produce the same
|
// MSVC std::hash<std::variant> does not use the index, thus produce the same
|
||||||
// result on the same value as different alternative.
|
// result on the same value as different alternative.
|
||||||
#if !(defined(_MSC_VER) && defined(ABSL_HAVE_STD_VARIANT))
|
#if !(defined(_MSC_VER) && defined(ABSL_USES_STD_VARIANT))
|
||||||
{
|
{
|
||||||
// same value as different alternative
|
// same value as different alternative
|
||||||
variant<int, int> v0(in_place_index<0>, 42);
|
variant<int, int> v0(in_place_index<0>, 42);
|
||||||
|
@ -2091,7 +2091,7 @@ TEST(VariantTest, Hash) {
|
||||||
std::hash<variant<int, int>> hash;
|
std::hash<variant<int, int>> hash;
|
||||||
EXPECT_NE(hash(v0), hash(v1));
|
EXPECT_NE(hash(v0), hash(v1));
|
||||||
}
|
}
|
||||||
#endif // !(defined(_MSC_VER) && defined(ABSL_HAVE_STD_VARIANT))
|
#endif // !(defined(_MSC_VER) && defined(ABSL_USES_STD_VARIANT))
|
||||||
|
|
||||||
{
|
{
|
||||||
std::hash<variant<int>> hash;
|
std::hash<variant<int>> hash;
|
||||||
|
@ -2118,7 +2118,7 @@ TEST(VariantTest, Hash) {
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|
||||||
// Test that a set requiring a basic type conversion works correctly
|
// Test that a set requiring a basic type conversion works correctly
|
||||||
#if !defined(ABSL_HAVE_STD_VARIANT)
|
#if !defined(ABSL_USES_STD_VARIANT)
|
||||||
TEST(VariantTest, TestConvertingSet) {
|
TEST(VariantTest, TestConvertingSet) {
|
||||||
typedef variant<double> Variant;
|
typedef variant<double> Variant;
|
||||||
Variant v(1.0);
|
Variant v(1.0);
|
||||||
|
@ -2128,7 +2128,7 @@ TEST(VariantTest, TestConvertingSet) {
|
||||||
ASSERT_TRUE(nullptr != absl::get_if<double>(&v));
|
ASSERT_TRUE(nullptr != absl::get_if<double>(&v));
|
||||||
EXPECT_DOUBLE_EQ(2, absl::get<double>(v));
|
EXPECT_DOUBLE_EQ(2, absl::get<double>(v));
|
||||||
}
|
}
|
||||||
#endif // ABSL_HAVE_STD_VARIANT
|
#endif // ABSL_USES_STD_VARIANT
|
||||||
|
|
||||||
// Test that a vector of variants behaves reasonably.
|
// Test that a vector of variants behaves reasonably.
|
||||||
TEST(VariantTest, Container) {
|
TEST(VariantTest, Container) {
|
||||||
|
@ -2280,7 +2280,7 @@ struct Convertible2 {
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST(VariantTest, TestRvalueConversion) {
|
TEST(VariantTest, TestRvalueConversion) {
|
||||||
#if !defined(ABSL_HAVE_STD_VARIANT)
|
#if !defined(ABSL_USES_STD_VARIANT)
|
||||||
variant<double, std::string> var(
|
variant<double, std::string> var(
|
||||||
ConvertVariantTo<variant<double, std::string>>(
|
ConvertVariantTo<variant<double, std::string>>(
|
||||||
variant<std::string, int>(0)));
|
variant<std::string, int>(0)));
|
||||||
|
@ -2313,7 +2313,7 @@ TEST(VariantTest, TestRvalueConversion) {
|
||||||
variant2 = ConvertVariantTo<variant<int32_t, uint32_t>>(variant<uint32_t>(42));
|
variant2 = ConvertVariantTo<variant<int32_t, uint32_t>>(variant<uint32_t>(42));
|
||||||
ASSERT_TRUE(absl::holds_alternative<uint32_t>(variant2));
|
ASSERT_TRUE(absl::holds_alternative<uint32_t>(variant2));
|
||||||
EXPECT_EQ(42, absl::get<uint32_t>(variant2));
|
EXPECT_EQ(42, absl::get<uint32_t>(variant2));
|
||||||
#endif // !ABSL_HAVE_STD_VARIANT
|
#endif // !ABSL_USES_STD_VARIANT
|
||||||
|
|
||||||
variant<Convertible1, Convertible2> variant3(
|
variant<Convertible1, Convertible2> variant3(
|
||||||
ConvertVariantTo<variant<Convertible1, Convertible2>>(
|
ConvertVariantTo<variant<Convertible1, Convertible2>>(
|
||||||
|
@ -2326,7 +2326,7 @@ TEST(VariantTest, TestRvalueConversion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(VariantTest, TestLvalueConversion) {
|
TEST(VariantTest, TestLvalueConversion) {
|
||||||
#if !defined(ABSL_HAVE_STD_VARIANT)
|
#if !defined(ABSL_USES_STD_VARIANT)
|
||||||
variant<std::string, int> source1 = 0;
|
variant<std::string, int> source1 = 0;
|
||||||
variant<double, std::string> destination(
|
variant<double, std::string> destination(
|
||||||
ConvertVariantTo<variant<double, std::string>>(source1));
|
ConvertVariantTo<variant<double, std::string>>(source1));
|
||||||
|
@ -2428,7 +2428,7 @@ TEST(VariantTest, DoesNotMoveFromLvalues) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(VariantTest, TestRvalueConversionViaConvertVariantTo) {
|
TEST(VariantTest, TestRvalueConversionViaConvertVariantTo) {
|
||||||
#if !defined(ABSL_HAVE_STD_VARIANT)
|
#if !defined(ABSL_USES_STD_VARIANT)
|
||||||
variant<double, std::string> var(
|
variant<double, std::string> var(
|
||||||
ConvertVariantTo<variant<double, std::string>>(
|
ConvertVariantTo<variant<double, std::string>>(
|
||||||
variant<std::string, int>(3)));
|
variant<std::string, int>(3)));
|
||||||
|
@ -2467,7 +2467,7 @@ TEST(VariantTest, TestRvalueConversionViaConvertVariantTo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(VariantTest, TestLvalueConversionViaConvertVariantTo) {
|
TEST(VariantTest, TestLvalueConversionViaConvertVariantTo) {
|
||||||
#if !defined(ABSL_HAVE_STD_VARIANT)
|
#if !defined(ABSL_USES_STD_VARIANT)
|
||||||
variant<std::string, int> source1 = 3;
|
variant<std::string, int> source1 = 3;
|
||||||
variant<double, std::string> destination(
|
variant<double, std::string> destination(
|
||||||
ConvertVariantTo<variant<double, std::string>>(source1));
|
ConvertVariantTo<variant<double, std::string>>(source1));
|
||||||
|
@ -2499,7 +2499,7 @@ TEST(VariantTest, TestLvalueConversionViaConvertVariantTo) {
|
||||||
variant<uint32_t> source6(42);
|
variant<uint32_t> source6(42);
|
||||||
variant2 = ConvertVariantTo<variant<int32_t, uint32_t>>(source6);
|
variant2 = ConvertVariantTo<variant<int32_t, uint32_t>>(source6);
|
||||||
EXPECT_THAT(absl::get_if<uint32_t>(&variant2), Pointee(42));
|
EXPECT_THAT(absl::get_if<uint32_t>(&variant2), Pointee(42));
|
||||||
#endif // !ABSL_HAVE_STD_VARIANT
|
#endif // !ABSL_USES_STD_VARIANT
|
||||||
|
|
||||||
variant<Convertible2, Convertible1> source7((Convertible1()));
|
variant<Convertible2, Convertible1> source7((Convertible1()));
|
||||||
variant<Convertible1, Convertible2> variant3(
|
variant<Convertible1, Convertible2> variant3(
|
||||||
|
@ -2533,7 +2533,7 @@ TEST(VariantTest, TestMoveConversionViaConvertVariantTo) {
|
||||||
// standard and we know that libstdc++ variant doesn't have this feature.
|
// standard and we know that libstdc++ variant doesn't have this feature.
|
||||||
// For more details see the paper:
|
// For more details see the paper:
|
||||||
// http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0602r0.html
|
// http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0602r0.html
|
||||||
#if !(defined(ABSL_HAVE_STD_VARIANT) && defined(__GLIBCXX__))
|
#if !(defined(ABSL_USES_STD_VARIANT) && defined(__GLIBCXX__))
|
||||||
#define ABSL_VARIANT_PROPAGATE_COPY_MOVE_TRIVIALITY 1
|
#define ABSL_VARIANT_PROPAGATE_COPY_MOVE_TRIVIALITY 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2711,4 +2711,4 @@ TEST(VariantTest, MoveCtorBug) {
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // #if !defined(ABSL_HAVE_STD_VARIANT)
|
#endif // #if !defined(ABSL_USES_STD_VARIANT)
|
||||||
|
|
|
@ -158,12 +158,12 @@ using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
|
||||||
|
|
||||||
// Tag types
|
// Tag types
|
||||||
|
|
||||||
#ifdef ABSL_HAVE_STD_OPTIONAL
|
#ifdef ABSL_USES_STD_OPTIONAL
|
||||||
|
|
||||||
using std::in_place_t;
|
using std::in_place_t;
|
||||||
using std::in_place;
|
using std::in_place;
|
||||||
|
|
||||||
#else // ABSL_HAVE_STD_OPTIONAL
|
#else // ABSL_USES_STD_OPTIONAL
|
||||||
|
|
||||||
// in_place_t
|
// in_place_t
|
||||||
//
|
//
|
||||||
|
@ -174,9 +174,9 @@ struct in_place_t {};
|
||||||
|
|
||||||
ABSL_INTERNAL_INLINE_CONSTEXPR(in_place_t, in_place, {});
|
ABSL_INTERNAL_INLINE_CONSTEXPR(in_place_t, in_place, {});
|
||||||
|
|
||||||
#endif // ABSL_HAVE_STD_OPTIONAL
|
#endif // ABSL_USES_STD_OPTIONAL
|
||||||
|
|
||||||
#if defined(ABSL_HAVE_STD_ANY) || defined(ABSL_HAVE_STD_VARIANT)
|
#if defined(ABSL_USES_STD_ANY) || defined(ABSL_USES_STD_VARIANT)
|
||||||
using std::in_place_type;
|
using std::in_place_type;
|
||||||
using std::in_place_type_t;
|
using std::in_place_type_t;
|
||||||
#else
|
#else
|
||||||
|
@ -191,9 +191,9 @@ using in_place_type_t = void (*)(utility_internal::InPlaceTypeTag<T>);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void in_place_type(utility_internal::InPlaceTypeTag<T>) {}
|
void in_place_type(utility_internal::InPlaceTypeTag<T>) {}
|
||||||
#endif // ABSL_HAVE_STD_ANY || ABSL_HAVE_STD_VARIANT
|
#endif // ABSL_USES_STD_ANY || ABSL_USES_STD_VARIANT
|
||||||
|
|
||||||
#ifdef ABSL_HAVE_STD_VARIANT
|
#ifdef ABSL_USES_STD_VARIANT
|
||||||
using std::in_place_index;
|
using std::in_place_index;
|
||||||
using std::in_place_index_t;
|
using std::in_place_index_t;
|
||||||
#else
|
#else
|
||||||
|
@ -208,7 +208,7 @@ using in_place_index_t = void (*)(utility_internal::InPlaceIndexTag<I>);
|
||||||
|
|
||||||
template <size_t I>
|
template <size_t I>
|
||||||
void in_place_index(utility_internal::InPlaceIndexTag<I>) {}
|
void in_place_index(utility_internal::InPlaceIndexTag<I>) {}
|
||||||
#endif // ABSL_HAVE_STD_VARIANT
|
#endif // ABSL_USES_STD_VARIANT
|
||||||
|
|
||||||
// Constexpr move and forward
|
// Constexpr move and forward
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue