a4b757b5d4
-- 693f81830b9f9cc8b24a1f38492b8dfcdd1d0e24 by Abseil Team <absl-team@google.com>: Check that absl::int128 works as a std::chrono::duration::rep. In particular, validate that ... std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<absl::int128, std::atto>> is a superset (range and resolution) of absl::Time. PiperOrigin-RevId: 283370280 -- df6073b686bd44223c6f9070fcceec918c728871 by Gennadiy Rozental <rogeeff@google.com>: Changes thread annotations to use DataGuard() function instead of a specific Mutex. Remove unused declaration of InvokeCallback. PiperOrigin-RevId: 283361188 -- b49eb2dd2ee1a0b4c8a7bb1a94e368b81ce5f861 by Abseil Team <absl-team@google.com>: Rewrite GetNominalCPUFrequency to use advapi32 instead of shlwapi Using shlwapi.dll means that gdi32.dll is loaded which then makes process destruction more expensive, which is unacceptable for some uses. There may be other places that pull in gdi32.dll - this just fixes the one. PiperOrigin-RevId: 282960698 -- b5508afec5099a0fdbb55e39a7cd2993259ed860 by Abseil Team <absl-team@google.com>: Small typo fix in comments: initiazliation -> initialization PiperOrigin-RevId: 282891800 -- 4319cc419584e91ee74f6ae1a32d88a412fc5c01 by Abseil Team <absl-team@google.com>: Update c_find_first_of() comment to remove the mention of an ordered container. PiperOrigin-RevId: 282836540 -- 5fcabc0a834dff39a505d5a5fc5403ddeb96028e by Derek Mauro <dmauro@google.com>: Fix NaCl build, where format checking is broken PiperOrigin-RevId: 282826202 -- aaf9ad3274c056a2f68e9b8ccada45c9802e2f1e by Derek Mauro <dmauro@google.com>: Fix more -Wundef warnings PiperOrigin-RevId: 282799820 -- 1fb06150a70ffe98bf4b2d42b2a39d083bf44f8c by Derek Mauro <dmauro@google.com>: Release support for additional platforms PiperOrigin-RevId: 282793384 -- fa947fc28624a316fa872d7045b3838b88a0d69b by Derek Mauro <dmauro@google.com>: Cleanup inconsistent usage of __has_attribute PiperOrigin-RevId: 282793296 -- 990030ad282263d6303c83b780a55fdec8e90d43 by Gennadiy Rozental <rogeeff@google.com>: Eliminate the pointer in absl::Flag, which points to n space where we were storing flag's default value. We also eliminate additional (now unnecessary) allocation for flag's default value. Instead we'll initialize the flags value directly from the value specified in ABSL_FLAG. If the default value is updated via the call to SetCommandLineOptionWithMode we are replacing pointer to initialization routine to pointer to new default value. PiperOrigin-RevId: 282637616 GitOrigin-RevId: 693f81830b9f9cc8b24a1f38492b8dfcdd1d0e24 Change-Id: I6f2edd8ef844de09aa2c182a7ca3133a22364792
216 lines
7.6 KiB
C++
216 lines
7.6 KiB
C++
//
|
|
// Copyright 2017 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: macros.h
|
|
// -----------------------------------------------------------------------------
|
|
//
|
|
// This header file defines the set of language macros used within Abseil code.
|
|
// For the set of macros used to determine supported compilers and platforms,
|
|
// see absl/base/config.h instead.
|
|
//
|
|
// This code is compiled directly on many platforms, including client
|
|
// platforms like Windows, Mac, and embedded systems. Before making
|
|
// any changes here, make sure that you're not breaking any platforms.
|
|
|
|
#ifndef ABSL_BASE_MACROS_H_
|
|
#define ABSL_BASE_MACROS_H_
|
|
|
|
#include <cassert>
|
|
#include <cstddef>
|
|
|
|
#include "absl/base/attributes.h"
|
|
#include "absl/base/optimization.h"
|
|
#include "absl/base/port.h"
|
|
|
|
// ABSL_ARRAYSIZE()
|
|
//
|
|
// Returns the number of elements in an array as a compile-time constant, which
|
|
// can be used in defining new arrays. If you use this macro on a pointer by
|
|
// mistake, you will get a compile-time error.
|
|
#define ABSL_ARRAYSIZE(array) \
|
|
(sizeof(::absl::macros_internal::ArraySizeHelper(array)))
|
|
|
|
namespace absl {
|
|
namespace macros_internal {
|
|
// Note: this internal template function declaration is used by ABSL_ARRAYSIZE.
|
|
// The function doesn't need a definition, as we only use its type.
|
|
template <typename T, size_t N>
|
|
auto ArraySizeHelper(const T (&array)[N]) -> char (&)[N];
|
|
} // namespace macros_internal
|
|
} // namespace absl
|
|
|
|
// kLinkerInitialized
|
|
//
|
|
// An enum used only as a constructor argument to indicate that a variable has
|
|
// static storage duration, and that the constructor should do nothing to its
|
|
// state. Use of this macro indicates to the reader that it is legal to
|
|
// declare a static instance of the class, provided the constructor is given
|
|
// the absl::base_internal::kLinkerInitialized argument.
|
|
//
|
|
// Normally, it is unsafe to declare a static variable that has a constructor or
|
|
// a destructor because invocation order is undefined. However, if the type can
|
|
// be zero-initialized (which the loader does for static variables) into a valid
|
|
// state and the type's destructor does not affect storage, then a constructor
|
|
// for static initialization can be declared.
|
|
//
|
|
// Example:
|
|
// // Declaration
|
|
// explicit MyClass(absl::base_internal:LinkerInitialized x) {}
|
|
//
|
|
// // Invocation
|
|
// static MyClass my_global(absl::base_internal::kLinkerInitialized);
|
|
namespace absl {
|
|
namespace base_internal {
|
|
enum LinkerInitialized {
|
|
kLinkerInitialized = 0,
|
|
};
|
|
} // namespace base_internal
|
|
} // namespace absl
|
|
|
|
// ABSL_FALLTHROUGH_INTENDED
|
|
//
|
|
// Annotates implicit fall-through between switch labels, allowing a case to
|
|
// indicate intentional fallthrough and turn off warnings about any lack of a
|
|
// `break` statement. The ABSL_FALLTHROUGH_INTENDED macro should be followed by
|
|
// a semicolon and can be used in most places where `break` can, provided that
|
|
// no statements exist between it and the next switch label.
|
|
//
|
|
// Example:
|
|
//
|
|
// switch (x) {
|
|
// case 40:
|
|
// case 41:
|
|
// if (truth_is_out_there) {
|
|
// ++x;
|
|
// ABSL_FALLTHROUGH_INTENDED; // Use instead of/along with annotations
|
|
// // in comments
|
|
// } else {
|
|
// return x;
|
|
// }
|
|
// case 42:
|
|
// ...
|
|
//
|
|
// Notes: when compiled with clang in C++11 mode, the ABSL_FALLTHROUGH_INTENDED
|
|
// macro is expanded to the [[clang::fallthrough]] attribute, which is analysed
|
|
// when performing switch labels fall-through diagnostic
|
|
// (`-Wimplicit-fallthrough`). See clang documentation on language extensions
|
|
// for details:
|
|
// http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
|
|
//
|
|
// When used with unsupported compilers, the ABSL_FALLTHROUGH_INTENDED macro
|
|
// has no effect on diagnostics. In any case this macro has no effect on runtime
|
|
// behavior and performance of code.
|
|
#ifdef ABSL_FALLTHROUGH_INTENDED
|
|
#error "ABSL_FALLTHROUGH_INTENDED should not be defined."
|
|
#endif
|
|
|
|
// TODO(zhangxy): Use c++17 standard [[fallthrough]] macro, when supported.
|
|
#if defined(__clang__) && defined(__has_warning)
|
|
#if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
|
|
#define ABSL_FALLTHROUGH_INTENDED [[clang::fallthrough]]
|
|
#endif
|
|
#elif defined(__GNUC__) && __GNUC__ >= 7
|
|
#define ABSL_FALLTHROUGH_INTENDED [[gnu::fallthrough]]
|
|
#endif
|
|
|
|
#ifndef ABSL_FALLTHROUGH_INTENDED
|
|
#define ABSL_FALLTHROUGH_INTENDED \
|
|
do { \
|
|
} while (0)
|
|
#endif
|
|
|
|
// ABSL_DEPRECATED()
|
|
//
|
|
// Marks a deprecated class, struct, enum, function, method and variable
|
|
// declarations. The macro argument is used as a custom diagnostic message (e.g.
|
|
// suggestion of a better alternative).
|
|
//
|
|
// Examples:
|
|
//
|
|
// class ABSL_DEPRECATED("Use Bar instead") Foo {...};
|
|
//
|
|
// ABSL_DEPRECATED("Use Baz() instead") void Bar() {...}
|
|
//
|
|
// template <typename T>
|
|
// ABSL_DEPRECATED("Use DoThat() instead")
|
|
// void DoThis();
|
|
//
|
|
// Every usage of a deprecated entity will trigger a warning when compiled with
|
|
// clang's `-Wdeprecated-declarations` option. This option is turned off by
|
|
// default, but the warnings will be reported by clang-tidy.
|
|
#if defined(__clang__) && __cplusplus >= 201103L
|
|
#define ABSL_DEPRECATED(message) __attribute__((deprecated(message)))
|
|
#endif
|
|
|
|
#ifndef ABSL_DEPRECATED
|
|
#define ABSL_DEPRECATED(message)
|
|
#endif
|
|
|
|
// ABSL_BAD_CALL_IF()
|
|
//
|
|
// Used on a function overload to trap bad calls: any call that matches the
|
|
// overload will cause a compile-time error. This macro uses a clang-specific
|
|
// "enable_if" attribute, as described at
|
|
// http://clang.llvm.org/docs/AttributeReference.html#enable-if
|
|
//
|
|
// Overloads which use this macro should be bracketed by
|
|
// `#ifdef ABSL_BAD_CALL_IF`.
|
|
//
|
|
// Example:
|
|
//
|
|
// int isdigit(int c);
|
|
// #ifdef ABSL_BAD_CALL_IF
|
|
// int isdigit(int c)
|
|
// ABSL_BAD_CALL_IF(c <= -1 || c > 255,
|
|
// "'c' must have the value of an unsigned char or EOF");
|
|
// #endif // ABSL_BAD_CALL_IF
|
|
#if ABSL_HAVE_ATTRIBUTE(enable_if)
|
|
#define ABSL_BAD_CALL_IF(expr, msg) \
|
|
__attribute__((enable_if(expr, "Bad call trap"), unavailable(msg)))
|
|
#endif
|
|
|
|
// ABSL_ASSERT()
|
|
//
|
|
// In C++11, `assert` can't be used portably within constexpr functions.
|
|
// ABSL_ASSERT functions as a runtime assert but works in C++11 constexpr
|
|
// functions. Example:
|
|
//
|
|
// constexpr double Divide(double a, double b) {
|
|
// return ABSL_ASSERT(b != 0), a / b;
|
|
// }
|
|
//
|
|
// This macro is inspired by
|
|
// https://akrzemi1.wordpress.com/2017/05/18/asserts-in-constexpr-functions/
|
|
#if defined(NDEBUG)
|
|
#define ABSL_ASSERT(expr) \
|
|
(false ? static_cast<void>(expr) : static_cast<void>(0))
|
|
#else
|
|
#define ABSL_ASSERT(expr) \
|
|
(ABSL_PREDICT_TRUE((expr)) ? static_cast<void>(0) \
|
|
: [] { assert(false && #expr); }()) // NOLINT
|
|
#endif
|
|
|
|
#ifdef ABSL_HAVE_EXCEPTIONS
|
|
#define ABSL_INTERNAL_TRY try
|
|
#define ABSL_INTERNAL_CATCH_ANY catch (...)
|
|
#define ABSL_INTERNAL_RETHROW do { throw; } while (false)
|
|
#else // ABSL_HAVE_EXCEPTIONS
|
|
#define ABSL_INTERNAL_TRY if (true)
|
|
#define ABSL_INTERNAL_CATCH_ANY else if (false)
|
|
#define ABSL_INTERNAL_RETHROW do {} while (false)
|
|
#endif // ABSL_HAVE_EXCEPTIONS
|
|
|
|
#endif // ABSL_BASE_MACROS_H_
|