blob: 3f7f32b9e6e32166b3905d9a19e777d360910cc5 [file] [log] [blame]
Austin Schuh36244a12019-09-21 17:52:38 -07001//
2// Copyright 2017 The Abseil Authors.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// https://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16// -----------------------------------------------------------------------------
17// File: config.h
18// -----------------------------------------------------------------------------
19//
20// This header file defines a set of macros for checking the presence of
21// important compiler and platform features. Such macros can be used to
22// produce portable code by parameterizing compilation based on the presence or
23// lack of a given feature.
24//
25// We define a "feature" as some interface we wish to program to: for example,
26// a library function or system call. A value of `1` indicates support for
27// that feature; any other value indicates the feature support is undefined.
28//
29// Example:
30//
31// Suppose a programmer wants to write a program that uses the 'mmap()' system
32// call. The Abseil macro for that feature (`ABSL_HAVE_MMAP`) allows you to
33// selectively include the `mmap.h` header and bracket code using that feature
34// in the macro:
35//
36// #include "absl/base/config.h"
37//
38// #ifdef ABSL_HAVE_MMAP
39// #include "sys/mman.h"
40// #endif //ABSL_HAVE_MMAP
41//
42// ...
43// #ifdef ABSL_HAVE_MMAP
44// void *ptr = mmap(...);
45// ...
46// #endif // ABSL_HAVE_MMAP
47
48#ifndef ABSL_BASE_CONFIG_H_
49#define ABSL_BASE_CONFIG_H_
50
51// Included for the __GLIBC__ macro (or similar macros on other systems).
52#include <limits.h>
53
54#ifdef __cplusplus
55// Included for __GLIBCXX__, _LIBCPP_VERSION
56#include <cstddef>
57#endif // __cplusplus
58
59#if defined(__APPLE__)
60// Included for TARGET_OS_IPHONE, __IPHONE_OS_VERSION_MIN_REQUIRED,
61// __IPHONE_8_0.
62#include <Availability.h>
63#include <TargetConditionals.h>
64#endif
65
Austin Schuhb4691e92020-12-31 12:37:18 -080066#include "absl/base/options.h"
Austin Schuh36244a12019-09-21 17:52:38 -070067#include "absl/base/policy_checks.h"
68
Austin Schuhb4691e92020-12-31 12:37:18 -080069// Helper macro to convert a CPP variable to a string literal.
70#define ABSL_INTERNAL_DO_TOKEN_STR(x) #x
71#define ABSL_INTERNAL_TOKEN_STR(x) ABSL_INTERNAL_DO_TOKEN_STR(x)
72
73// -----------------------------------------------------------------------------
74// Abseil namespace annotations
75// -----------------------------------------------------------------------------
76
77// ABSL_NAMESPACE_BEGIN/ABSL_NAMESPACE_END
78//
79// An annotation placed at the beginning/end of each `namespace absl` scope.
80// This is used to inject an inline namespace.
81//
82// The proper way to write Abseil code in the `absl` namespace is:
83//
84// namespace absl {
85// ABSL_NAMESPACE_BEGIN
86//
87// void Foo(); // absl::Foo().
88//
89// ABSL_NAMESPACE_END
90// } // namespace absl
91//
92// Users of Abseil should not use these macros, because users of Abseil should
93// not write `namespace absl {` in their own code for any reason. (Abseil does
94// not support forward declarations of its own types, nor does it support
95// user-provided specialization of Abseil templates. Code that violates these
96// rules may be broken without warning.)
97#if !defined(ABSL_OPTION_USE_INLINE_NAMESPACE) || \
98 !defined(ABSL_OPTION_INLINE_NAMESPACE_NAME)
99#error options.h is misconfigured.
100#endif
101
102// Check that ABSL_OPTION_INLINE_NAMESPACE_NAME is neither "head" nor ""
103#if defined(__cplusplus) && ABSL_OPTION_USE_INLINE_NAMESPACE == 1
104
105#define ABSL_INTERNAL_INLINE_NAMESPACE_STR \
106 ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME)
107
108static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != '\0',
109 "options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must "
110 "not be empty.");
111static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
112 ABSL_INTERNAL_INLINE_NAMESPACE_STR[1] != 'e' ||
113 ABSL_INTERNAL_INLINE_NAMESPACE_STR[2] != 'a' ||
114 ABSL_INTERNAL_INLINE_NAMESPACE_STR[3] != 'd' ||
115 ABSL_INTERNAL_INLINE_NAMESPACE_STR[4] != '\0',
116 "options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must "
117 "be changed to a new, unique identifier name.");
118
119#endif
120
121#if ABSL_OPTION_USE_INLINE_NAMESPACE == 0
122#define ABSL_NAMESPACE_BEGIN
123#define ABSL_NAMESPACE_END
124#elif ABSL_OPTION_USE_INLINE_NAMESPACE == 1
125#define ABSL_NAMESPACE_BEGIN \
126 inline namespace ABSL_OPTION_INLINE_NAMESPACE_NAME {
127#define ABSL_NAMESPACE_END }
128#else
129#error options.h is misconfigured.
130#endif
131
Austin Schuh36244a12019-09-21 17:52:38 -0700132// -----------------------------------------------------------------------------
133// Compiler Feature Checks
134// -----------------------------------------------------------------------------
135
136// ABSL_HAVE_BUILTIN()
137//
138// Checks whether the compiler supports a Clang Feature Checking Macro, and if
139// so, checks whether it supports the provided builtin function "x" where x
140// is one of the functions noted in
141// https://clang.llvm.org/docs/LanguageExtensions.html
142//
143// Note: Use this macro to avoid an extra level of #ifdef __has_builtin check.
144// http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html
145#ifdef __has_builtin
146#define ABSL_HAVE_BUILTIN(x) __has_builtin(x)
147#else
148#define ABSL_HAVE_BUILTIN(x) 0
149#endif
150
Austin Schuhb4691e92020-12-31 12:37:18 -0800151#if defined(__is_identifier)
152#define ABSL_INTERNAL_HAS_KEYWORD(x) !(__is_identifier(x))
153#else
154#define ABSL_INTERNAL_HAS_KEYWORD(x) 0
155#endif
156
157#ifdef __has_feature
158#define ABSL_HAVE_FEATURE(f) __has_feature(f)
159#else
160#define ABSL_HAVE_FEATURE(f) 0
161#endif
162
Austin Schuh36244a12019-09-21 17:52:38 -0700163// ABSL_HAVE_TLS is defined to 1 when __thread should be supported.
164// We assume __thread is supported on Linux when compiled with Clang or compiled
165// against libstdc++ with _GLIBCXX_HAVE_TLS defined.
166#ifdef ABSL_HAVE_TLS
167#error ABSL_HAVE_TLS cannot be directly set
168#elif defined(__linux__) && (defined(__clang__) || defined(_GLIBCXX_HAVE_TLS))
169#define ABSL_HAVE_TLS 1
170#endif
171
172// ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
173//
174// Checks whether `std::is_trivially_destructible<T>` is supported.
175//
176// Notes: All supported compilers using libc++ support this feature, as does
177// gcc >= 4.8.1 using libstdc++, and Visual Studio.
178#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
179#error ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set
180#elif defined(_LIBCPP_VERSION) || \
181 (!defined(__clang__) && defined(__GNUC__) && defined(__GLIBCXX__) && \
182 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) || \
183 defined(_MSC_VER)
184#define ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
185#endif
186
187// ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
188//
189// Checks whether `std::is_trivially_default_constructible<T>` and
190// `std::is_trivially_copy_constructible<T>` are supported.
191
192// ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
193//
194// Checks whether `std::is_trivially_copy_assignable<T>` is supported.
195
196// Notes: Clang with libc++ supports these features, as does gcc >= 5.1 with
197// either libc++ or libstdc++, and Visual Studio (but not NVCC).
198#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE)
199#error ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE cannot be directly set
200#elif defined(ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE)
201#error ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot directly set
202#elif (defined(__clang__) && defined(_LIBCPP_VERSION)) || \
203 (!defined(__clang__) && defined(__GNUC__) && \
204 (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 4)) && \
205 (defined(_LIBCPP_VERSION) || defined(__GLIBCXX__))) || \
206 (defined(_MSC_VER) && !defined(__NVCC__))
207#define ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 1
208#define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1
209#endif
210
Austin Schuhb4691e92020-12-31 12:37:18 -0800211// ABSL_HAVE_SOURCE_LOCATION_CURRENT
212//
213// Indicates whether `absl::SourceLocation::current()` will return useful
214// information in some contexts.
215#ifndef ABSL_HAVE_SOURCE_LOCATION_CURRENT
216#if ABSL_INTERNAL_HAS_KEYWORD(__builtin_LINE) && \
217 ABSL_INTERNAL_HAS_KEYWORD(__builtin_FILE)
218#define ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
219#endif
220#endif
221
Austin Schuh36244a12019-09-21 17:52:38 -0700222// ABSL_HAVE_THREAD_LOCAL
223//
224// Checks whether C++11's `thread_local` storage duration specifier is
225// supported.
226#ifdef ABSL_HAVE_THREAD_LOCAL
227#error ABSL_HAVE_THREAD_LOCAL cannot be directly set
228#elif defined(__APPLE__)
229// Notes:
230// * Xcode's clang did not support `thread_local` until version 8, and
231// even then not for all iOS < 9.0.
232// * Xcode 9.3 started disallowing `thread_local` for 32-bit iOS simulator
233// targeting iOS 9.x.
234// * Xcode 10 moves the deployment target check for iOS < 9.0 to link time
Austin Schuhb4691e92020-12-31 12:37:18 -0800235// making ABSL_HAVE_FEATURE unreliable there.
Austin Schuh36244a12019-09-21 17:52:38 -0700236//
Austin Schuhb4691e92020-12-31 12:37:18 -0800237#if ABSL_HAVE_FEATURE(cxx_thread_local) && \
Austin Schuh36244a12019-09-21 17:52:38 -0700238 !(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
239#define ABSL_HAVE_THREAD_LOCAL 1
240#endif
241#else // !defined(__APPLE__)
242#define ABSL_HAVE_THREAD_LOCAL 1
243#endif
244
245// There are platforms for which TLS should not be used even though the compiler
246// makes it seem like it's supported (Android NDK < r12b for example).
247// This is primarily because of linker problems and toolchain misconfiguration:
248// Abseil does not intend to support this indefinitely. Currently, the newest
249// toolchain that we intend to support that requires this behavior is the
250// r11 NDK - allowing for a 5 year support window on that means this option
251// is likely to be removed around June of 2021.
252// TLS isn't supported until NDK r12b per
253// https://developer.android.com/ndk/downloads/revision_history.html
254// Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
255// <android/ndk-version.h>. For NDK < r16, users should define these macros,
256// e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11.
257#if defined(__ANDROID__) && defined(__clang__)
258#if __has_include(<android/ndk-version.h>)
259#include <android/ndk-version.h>
260#endif // __has_include(<android/ndk-version.h>)
261#if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \
262 defined(__NDK_MINOR__) && \
263 ((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))
264#undef ABSL_HAVE_TLS
265#undef ABSL_HAVE_THREAD_LOCAL
266#endif
267#endif // defined(__ANDROID__) && defined(__clang__)
268
Austin Schuh36244a12019-09-21 17:52:38 -0700269// ABSL_HAVE_INTRINSIC_INT128
270//
271// Checks whether the __int128 compiler extension for a 128-bit integral type is
272// supported.
273//
274// Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is
275// supported, but we avoid using it in certain cases:
276// * On Clang:
277// * Building using Clang for Windows, where the Clang runtime library has
278// 128-bit support only on LP64 architectures, but Windows is LLP64.
279// * On Nvidia's nvcc:
280// * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions
281// actually support __int128.
282#ifdef ABSL_HAVE_INTRINSIC_INT128
283#error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set
284#elif defined(__SIZEOF_INT128__)
285#if (defined(__clang__) && !defined(_WIN32)) || \
286 (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \
287 (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__))
288#define ABSL_HAVE_INTRINSIC_INT128 1
289#elif defined(__CUDACC__)
290// __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
291// string explaining that it has been removed starting with CUDA 9. We use
292// nested #ifs because there is no short-circuiting in the preprocessor.
293// NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
294#if __CUDACC_VER__ >= 70000
295#define ABSL_HAVE_INTRINSIC_INT128 1
296#endif // __CUDACC_VER__ >= 70000
297#endif // defined(__CUDACC__)
298#endif // ABSL_HAVE_INTRINSIC_INT128
299
300// ABSL_HAVE_EXCEPTIONS
301//
302// Checks whether the compiler both supports and enables exceptions. Many
303// compilers support a "no exceptions" mode that disables exceptions.
304//
305// Generally, when ABSL_HAVE_EXCEPTIONS is not defined:
306//
307// * Code using `throw` and `try` may not compile.
308// * The `noexcept` specifier will still compile and behave as normal.
309// * The `noexcept` operator may still return `false`.
310//
311// For further details, consult the compiler's documentation.
312#ifdef ABSL_HAVE_EXCEPTIONS
313#error ABSL_HAVE_EXCEPTIONS cannot be directly set.
314
315#elif defined(__clang__)
Austin Schuhb4691e92020-12-31 12:37:18 -0800316
317#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
318// Clang >= 3.6
319#if ABSL_HAVE_FEATURE(cxx_exceptions)
Austin Schuh36244a12019-09-21 17:52:38 -0700320#define ABSL_HAVE_EXCEPTIONS 1
Austin Schuhb4691e92020-12-31 12:37:18 -0800321#endif // ABSL_HAVE_FEATURE(cxx_exceptions)
322#else
323// Clang < 3.6
324// http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
325#if defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions)
326#define ABSL_HAVE_EXCEPTIONS 1
327#endif // defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions)
328#endif // __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
Austin Schuh36244a12019-09-21 17:52:38 -0700329
330// Handle remaining special cases and default to exceptions being supported.
331#elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) && \
332 !(defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__cpp_exceptions)) && \
333 !(defined(_MSC_VER) && !defined(_CPPUNWIND))
334#define ABSL_HAVE_EXCEPTIONS 1
335#endif
336
337// -----------------------------------------------------------------------------
338// Platform Feature Checks
339// -----------------------------------------------------------------------------
340
341// Currently supported operating systems and associated preprocessor
342// symbols:
343//
344// Linux and Linux-derived __linux__
345// Android __ANDROID__ (implies __linux__)
346// Linux (non-Android) __linux__ && !__ANDROID__
347// Darwin (macOS and iOS) __APPLE__
348// Akaros (http://akaros.org) __ros__
349// Windows _WIN32
350// NaCL __native_client__
351// AsmJS __asmjs__
352// WebAssembly __wasm__
353// Fuchsia __Fuchsia__
354//
355// Note that since Android defines both __ANDROID__ and __linux__, one
356// may probe for either Linux or Android by simply testing for __linux__.
357
358// ABSL_HAVE_MMAP
359//
360// Checks whether the platform has an mmap(2) implementation as defined in
361// POSIX.1-2001.
362#ifdef ABSL_HAVE_MMAP
363#error ABSL_HAVE_MMAP cannot be directly set
364#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
365 defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
366 defined(__wasm__) || defined(__Fuchsia__) || defined(__sun) || \
Austin Schuhb4691e92020-12-31 12:37:18 -0800367 defined(__ASYLO__) || defined(__myriad2__)
Austin Schuh36244a12019-09-21 17:52:38 -0700368#define ABSL_HAVE_MMAP 1
369#endif
370
371// ABSL_HAVE_PTHREAD_GETSCHEDPARAM
372//
373// Checks whether the platform implements the pthread_(get|set)schedparam(3)
374// functions as defined in POSIX.1-2001.
375#ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM
376#error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
377#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
378 defined(__ros__)
379#define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
380#endif
381
382// ABSL_HAVE_SCHED_YIELD
383//
384// Checks whether the platform implements sched_yield(2) as defined in
385// POSIX.1-2001.
386#ifdef ABSL_HAVE_SCHED_YIELD
387#error ABSL_HAVE_SCHED_YIELD cannot be directly set
388#elif defined(__linux__) || defined(__ros__) || defined(__native_client__)
389#define ABSL_HAVE_SCHED_YIELD 1
390#endif
391
392// ABSL_HAVE_SEMAPHORE_H
393//
Austin Schuhb4691e92020-12-31 12:37:18 -0800394// Checks whether the platform supports the <semaphore.h> header and sem_init(3)
Austin Schuh36244a12019-09-21 17:52:38 -0700395// family of functions as standardized in POSIX.1-2001.
396//
397// Note: While Apple provides <semaphore.h> for both iOS and macOS, it is
398// explicitly deprecated and will cause build failures if enabled for those
399// platforms. We side-step the issue by not defining it here for Apple
400// platforms.
401#ifdef ABSL_HAVE_SEMAPHORE_H
402#error ABSL_HAVE_SEMAPHORE_H cannot be directly set
403#elif defined(__linux__) || defined(__ros__)
404#define ABSL_HAVE_SEMAPHORE_H 1
405#endif
406
407// ABSL_HAVE_ALARM
408//
409// Checks whether the platform supports the <signal.h> header and alarm(2)
410// function as standardized in POSIX.1-2001.
411#ifdef ABSL_HAVE_ALARM
412#error ABSL_HAVE_ALARM cannot be directly set
413#elif defined(__GOOGLE_GRTE_VERSION__)
414// feature tests for Google's GRTE
415#define ABSL_HAVE_ALARM 1
416#elif defined(__GLIBC__)
417// feature test for glibc
418#define ABSL_HAVE_ALARM 1
419#elif defined(_MSC_VER)
420// feature tests for Microsoft's library
Austin Schuhb4691e92020-12-31 12:37:18 -0800421#elif defined(__MINGW32__)
422// mingw32 doesn't provide alarm(2):
423// https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.2-trunk/mingwrt/include/unistd.h
424// mingw-w64 provides a no-op implementation:
425// https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/alarm.c
Austin Schuh36244a12019-09-21 17:52:38 -0700426#elif defined(__EMSCRIPTEN__)
427// emscripten doesn't support signals
428#elif defined(__Fuchsia__)
429// Signals don't exist on fuchsia.
430#elif defined(__native_client__)
431#else
432// other standard libraries
433#define ABSL_HAVE_ALARM 1
434#endif
435
436// ABSL_IS_LITTLE_ENDIAN
437// ABSL_IS_BIG_ENDIAN
438//
439// Checks the endianness of the platform.
440//
441// Notes: uses the built in endian macros provided by GCC (since 4.6) and
442// Clang (since 3.2); see
443// https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html.
444// Otherwise, if _WIN32, assume little endian. Otherwise, bail with an error.
445#if defined(ABSL_IS_BIG_ENDIAN)
446#error "ABSL_IS_BIG_ENDIAN cannot be directly set."
447#endif
448#if defined(ABSL_IS_LITTLE_ENDIAN)
449#error "ABSL_IS_LITTLE_ENDIAN cannot be directly set."
450#endif
451
452#if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
453 __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
454#define ABSL_IS_LITTLE_ENDIAN 1
455#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
456 __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
457#define ABSL_IS_BIG_ENDIAN 1
458#elif defined(_WIN32)
459#define ABSL_IS_LITTLE_ENDIAN 1
460#else
461#error "absl endian detection needs to be set up for your compiler"
462#endif
463
464// macOS 10.13 and iOS 10.11 don't let you use <any>, <optional>, or <variant>
465// even though the headers exist and are publicly noted to work. See
466// https://github.com/abseil/abseil-cpp/issues/207 and
467// https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
468// libc++ spells out the availability requirements in the file
469// llvm-project/libcxx/include/__config via the #define
470// _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS.
471#if defined(__APPLE__) && defined(_LIBCPP_VERSION) && \
472 ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
473 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101400) || \
474 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
475 __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 120000) || \
476 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
Austin Schuhb4691e92020-12-31 12:37:18 -0800477 __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 50000) || \
Austin Schuh36244a12019-09-21 17:52:38 -0700478 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && \
Austin Schuhb4691e92020-12-31 12:37:18 -0800479 __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 120000))
Austin Schuh36244a12019-09-21 17:52:38 -0700480#define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 1
481#else
482#define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 0
483#endif
484
485// ABSL_HAVE_STD_ANY
486//
487// Checks whether C++17 std::any is available by checking whether <any> exists.
488#ifdef ABSL_HAVE_STD_ANY
489#error "ABSL_HAVE_STD_ANY cannot be directly set."
490#endif
491
492#ifdef __has_include
493#if __has_include(<any>) && __cplusplus >= 201703L && \
494 !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
495#define ABSL_HAVE_STD_ANY 1
496#endif
497#endif
498
499// ABSL_HAVE_STD_OPTIONAL
500//
501// Checks whether C++17 std::optional is available.
502#ifdef ABSL_HAVE_STD_OPTIONAL
503#error "ABSL_HAVE_STD_OPTIONAL cannot be directly set."
504#endif
505
506#ifdef __has_include
507#if __has_include(<optional>) && __cplusplus >= 201703L && \
508 !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
509#define ABSL_HAVE_STD_OPTIONAL 1
510#endif
511#endif
512
513// ABSL_HAVE_STD_VARIANT
514//
515// Checks whether C++17 std::variant is available.
516#ifdef ABSL_HAVE_STD_VARIANT
517#error "ABSL_HAVE_STD_VARIANT cannot be directly set."
518#endif
519
520#ifdef __has_include
521#if __has_include(<variant>) && __cplusplus >= 201703L && \
522 !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
523#define ABSL_HAVE_STD_VARIANT 1
524#endif
525#endif
526
527// ABSL_HAVE_STD_STRING_VIEW
528//
529// Checks whether C++17 std::string_view is available.
530#ifdef ABSL_HAVE_STD_STRING_VIEW
531#error "ABSL_HAVE_STD_STRING_VIEW cannot be directly set."
532#endif
533
534#ifdef __has_include
535#if __has_include(<string_view>) && __cplusplus >= 201703L
536#define ABSL_HAVE_STD_STRING_VIEW 1
537#endif
538#endif
539
540// For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than
541// the support for <optional>, <any>, <string_view>, <variant>. So we use
542// _MSC_VER to check whether we have VS 2017 RTM (when <optional>, <any>,
543// <string_view>, <variant> is implemented) or higher. Also, `__cplusplus` is
544// not correctly set by MSVC, so we use `_MSVC_LANG` to check the language
545// version.
546// TODO(zhangxy): fix tests before enabling aliasing for `std::any`.
547#if defined(_MSC_VER) && _MSC_VER >= 1910 && \
548 ((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || __cplusplus > 201402)
549// #define ABSL_HAVE_STD_ANY 1
550#define ABSL_HAVE_STD_OPTIONAL 1
551#define ABSL_HAVE_STD_VARIANT 1
552#define ABSL_HAVE_STD_STRING_VIEW 1
553#endif
554
Austin Schuhb4691e92020-12-31 12:37:18 -0800555// ABSL_USES_STD_ANY
556//
557// Indicates whether absl::any is an alias for std::any.
558#if !defined(ABSL_OPTION_USE_STD_ANY)
559#error options.h is misconfigured.
560#elif ABSL_OPTION_USE_STD_ANY == 0 || \
561 (ABSL_OPTION_USE_STD_ANY == 2 && !defined(ABSL_HAVE_STD_ANY))
562#undef ABSL_USES_STD_ANY
563#elif ABSL_OPTION_USE_STD_ANY == 1 || \
564 (ABSL_OPTION_USE_STD_ANY == 2 && defined(ABSL_HAVE_STD_ANY))
565#define ABSL_USES_STD_ANY 1
566#else
567#error options.h is misconfigured.
568#endif
569
570// ABSL_USES_STD_OPTIONAL
571//
572// Indicates whether absl::optional is an alias for std::optional.
573#if !defined(ABSL_OPTION_USE_STD_OPTIONAL)
574#error options.h is misconfigured.
575#elif ABSL_OPTION_USE_STD_OPTIONAL == 0 || \
576 (ABSL_OPTION_USE_STD_OPTIONAL == 2 && !defined(ABSL_HAVE_STD_OPTIONAL))
577#undef ABSL_USES_STD_OPTIONAL
578#elif ABSL_OPTION_USE_STD_OPTIONAL == 1 || \
579 (ABSL_OPTION_USE_STD_OPTIONAL == 2 && defined(ABSL_HAVE_STD_OPTIONAL))
580#define ABSL_USES_STD_OPTIONAL 1
581#else
582#error options.h is misconfigured.
583#endif
584
585// ABSL_USES_STD_VARIANT
586//
587// Indicates whether absl::variant is an alias for std::variant.
588#if !defined(ABSL_OPTION_USE_STD_VARIANT)
589#error options.h is misconfigured.
590#elif ABSL_OPTION_USE_STD_VARIANT == 0 || \
591 (ABSL_OPTION_USE_STD_VARIANT == 2 && !defined(ABSL_HAVE_STD_VARIANT))
592#undef ABSL_USES_STD_VARIANT
593#elif ABSL_OPTION_USE_STD_VARIANT == 1 || \
594 (ABSL_OPTION_USE_STD_VARIANT == 2 && defined(ABSL_HAVE_STD_VARIANT))
595#define ABSL_USES_STD_VARIANT 1
596#else
597#error options.h is misconfigured.
598#endif
599
600// ABSL_USES_STD_STRING_VIEW
601//
602// Indicates whether absl::string_view is an alias for std::string_view.
603#if !defined(ABSL_OPTION_USE_STD_STRING_VIEW)
604#error options.h is misconfigured.
605#elif ABSL_OPTION_USE_STD_STRING_VIEW == 0 || \
606 (ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
607 !defined(ABSL_HAVE_STD_STRING_VIEW))
608#undef ABSL_USES_STD_STRING_VIEW
609#elif ABSL_OPTION_USE_STD_STRING_VIEW == 1 || \
610 (ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
611 defined(ABSL_HAVE_STD_STRING_VIEW))
612#define ABSL_USES_STD_STRING_VIEW 1
613#else
614#error options.h is misconfigured.
615#endif
616
Austin Schuh36244a12019-09-21 17:52:38 -0700617// In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
618// SEH exception from emplace for variant<SomeStruct> when constructing the
619// struct can throw. This defeats some of variant_test and
620// variant_exception_safety_test.
621#if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG)
622#define ABSL_INTERNAL_MSVC_2017_DBG_MODE
623#endif
624
Austin Schuhb4691e92020-12-31 12:37:18 -0800625// ABSL_INTERNAL_MANGLED_NS
626// ABSL_INTERNAL_MANGLED_BACKREFERENCE
627//
628// Internal macros for building up mangled names in our internal fork of CCTZ.
629// This implementation detail is only needed and provided for the MSVC build.
630//
631// These macros both expand to string literals. ABSL_INTERNAL_MANGLED_NS is
632// the mangled spelling of the `absl` namespace, and
633// ABSL_INTERNAL_MANGLED_BACKREFERENCE is a back-reference integer representing
634// the proper count to skip past the CCTZ fork namespace names. (This number
635// is one larger when there is an inline namespace name to skip.)
636#if defined(_MSC_VER)
637#if ABSL_OPTION_USE_INLINE_NAMESPACE == 0
638#define ABSL_INTERNAL_MANGLED_NS "absl"
639#define ABSL_INTERNAL_MANGLED_BACKREFERENCE "5"
640#else
641#define ABSL_INTERNAL_MANGLED_NS \
642 ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME) "@absl"
643#define ABSL_INTERNAL_MANGLED_BACKREFERENCE "6"
644#endif
645#endif
646
647#undef ABSL_INTERNAL_HAS_KEYWORD
648
649// ABSL_DLL
650//
651// When building Abseil as a DLL, this macro expands to `__declspec(dllexport)`
652// so we can annotate symbols appropriately as being exported. When used in
653// headers consuming a DLL, this macro expands to `__declspec(dllimport)` so
654// that consumers know the symbol is defined inside the DLL. In all other cases,
655// the macro expands to nothing.
656#if defined(_MSC_VER)
657#if defined(ABSL_BUILD_DLL)
658#define ABSL_DLL __declspec(dllexport)
659#elif defined(ABSL_CONSUME_DLL)
660#define ABSL_DLL __declspec(dllimport)
661#else
662#define ABSL_DLL
663#endif
664#else
665#define ABSL_DLL
666#endif // defined(_MSC_VER)
667
668// ABSL_HAVE_MEMORY_SANITIZER
669//
670// MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
671// a compiler instrumentation module and a run-time library.
672#ifdef ABSL_HAVE_MEMORY_SANITIZER
673#error "ABSL_HAVE_MEMORY_SANITIZER cannot be directly set."
674#elif defined(MEMORY_SANITIZER)
675// The MEMORY_SANITIZER macro is deprecated but we will continue to honor it
676// for now.
677#define ABSL_HAVE_MEMORY_SANITIZER 1
678#elif defined(__SANITIZE_MEMORY__)
679#define ABSL_HAVE_MEMORY_SANITIZER 1
680#elif !defined(__native_client__) && ABSL_HAVE_FEATURE(memory_sanitizer)
681#define ABSL_HAVE_MEMORY_SANITIZER 1
682#endif
683
684// ABSL_HAVE_THREAD_SANITIZER
685//
686// ThreadSanitizer (TSan) is a fast data race detector.
687#ifdef ABSL_HAVE_THREAD_SANITIZER
688#error "ABSL_HAVE_THREAD_SANITIZER cannot be directly set."
689#elif defined(THREAD_SANITIZER)
690// The THREAD_SANITIZER macro is deprecated but we will continue to honor it
691// for now.
692#define ABSL_HAVE_THREAD_SANITIZER 1
693#elif defined(__SANITIZE_THREAD__)
694#define ABSL_HAVE_THREAD_SANITIZER 1
695#elif ABSL_HAVE_FEATURE(thread_sanitizer)
696#define ABSL_HAVE_THREAD_SANITIZER 1
697#endif
698
699// ABSL_HAVE_ADDRESS_SANITIZER
700//
701// AddressSanitizer (ASan) is a fast memory error detector.
702#ifdef ABSL_HAVE_ADDRESS_SANITIZER
703#error "ABSL_HAVE_ADDRESS_SANITIZER cannot be directly set."
704#elif defined(ADDRESS_SANITIZER)
705// The ADDRESS_SANITIZER macro is deprecated but we will continue to honor it
706// for now.
707#define ABSL_HAVE_ADDRESS_SANITIZER 1
708#elif defined(__SANITIZE_ADDRESS__)
709#define ABSL_HAVE_ADDRESS_SANITIZER 1
710#elif ABSL_HAVE_FEATURE(address_sanitizer)
711#define ABSL_HAVE_ADDRESS_SANITIZER 1
712#endif
713
Austin Schuh36244a12019-09-21 17:52:38 -0700714#endif // ABSL_BASE_CONFIG_H_