• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
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 
66 #include "absl/base/options.h"
67 #include "absl/base/policy_checks.h"
68 
69 // 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 
108 static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != '\0',
109               "options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must "
110               "not be empty.");
111 static_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 #define ABSL_INTERNAL_C_SYMBOL(x) x
125 #elif ABSL_OPTION_USE_INLINE_NAMESPACE == 1
126 #define ABSL_NAMESPACE_BEGIN \
127   inline namespace ABSL_OPTION_INLINE_NAMESPACE_NAME {
128 #define ABSL_NAMESPACE_END }
129 #define ABSL_INTERNAL_C_SYMBOL_HELPER_2(x, v) x##_##v
130 #define ABSL_INTERNAL_C_SYMBOL_HELPER_1(x, v) \
131   ABSL_INTERNAL_C_SYMBOL_HELPER_2(x, v)
132 #define ABSL_INTERNAL_C_SYMBOL(x) \
133   ABSL_INTERNAL_C_SYMBOL_HELPER_1(x, ABSL_OPTION_INLINE_NAMESPACE_NAME)
134 #else
135 #error options.h is misconfigured.
136 #endif
137 
138 // -----------------------------------------------------------------------------
139 // Compiler Feature Checks
140 // -----------------------------------------------------------------------------
141 
142 // ABSL_HAVE_BUILTIN()
143 //
144 // Checks whether the compiler supports a Clang Feature Checking Macro, and if
145 // so, checks whether it supports the provided builtin function "x" where x
146 // is one of the functions noted in
147 // https://clang.llvm.org/docs/LanguageExtensions.html
148 //
149 // Note: Use this macro to avoid an extra level of #ifdef __has_builtin check.
150 // http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html
151 #ifdef __has_builtin
152 #define ABSL_HAVE_BUILTIN(x) __has_builtin(x)
153 #else
154 #define ABSL_HAVE_BUILTIN(x) 0
155 #endif
156 
157 #if defined(__is_identifier)
158 #define ABSL_INTERNAL_HAS_KEYWORD(x) !(__is_identifier(x))
159 #else
160 #define ABSL_INTERNAL_HAS_KEYWORD(x) 0
161 #endif
162 
163 #ifdef __has_feature
164 #define ABSL_HAVE_FEATURE(f) __has_feature(f)
165 #else
166 #define ABSL_HAVE_FEATURE(f) 0
167 #endif
168 
169 // ABSL_HAVE_TLS is defined to 1 when __thread should be supported.
170 // We assume __thread is supported on Linux when compiled with Clang or compiled
171 // against libstdc++ with _GLIBCXX_HAVE_TLS defined.
172 #ifdef ABSL_HAVE_TLS
173 #error ABSL_HAVE_TLS cannot be directly set
174 #elif defined(__linux__) && (defined(__clang__) || defined(_GLIBCXX_HAVE_TLS))
175 #define ABSL_HAVE_TLS 1
176 #endif
177 
178 // ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
179 //
180 // Checks whether `std::is_trivially_destructible<T>` is supported.
181 //
182 // Notes: All supported compilers using libc++ support this feature, as does
183 // gcc >= 4.8.1 using libstdc++, and Visual Studio.
184 #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
185 #error ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set
186 #elif defined(_LIBCPP_VERSION) ||                                        \
187     (!defined(__clang__) && defined(__GNUC__) && defined(__GLIBCXX__) && \
188      (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) ||        \
189     defined(_MSC_VER)
190 #define ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
191 #endif
192 
193 // ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
194 //
195 // Checks whether `std::is_trivially_default_constructible<T>` and
196 // `std::is_trivially_copy_constructible<T>` are supported.
197 
198 // ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
199 //
200 // Checks whether `std::is_trivially_copy_assignable<T>` is supported.
201 
202 // Notes: Clang with libc++ supports these features, as does gcc >= 5.1 with
203 // either libc++ or libstdc++, and Visual Studio (but not NVCC).
204 #if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE)
205 #error ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE cannot be directly set
206 #elif defined(ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE)
207 #error ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot directly set
208 #elif (defined(__clang__) && defined(_LIBCPP_VERSION)) ||        \
209     (!defined(__clang__) && defined(__GNUC__) &&                 \
210      (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 4)) && \
211      (defined(_LIBCPP_VERSION) || defined(__GLIBCXX__))) ||      \
212     (defined(_MSC_VER) && !defined(__NVCC__))
213 #define ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 1
214 #define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1
215 #endif
216 
217 // ABSL_HAVE_SOURCE_LOCATION_CURRENT
218 //
219 // Indicates whether `absl::SourceLocation::current()` will return useful
220 // information in some contexts.
221 #ifndef ABSL_HAVE_SOURCE_LOCATION_CURRENT
222 #if ABSL_INTERNAL_HAS_KEYWORD(__builtin_LINE) && \
223     ABSL_INTERNAL_HAS_KEYWORD(__builtin_FILE)
224 #define ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
225 #elif defined(__GNUC__) && __GNUC__ >= 5
226 #define ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
227 #endif
228 #endif
229 
230 // ABSL_HAVE_THREAD_LOCAL
231 //
232 // Checks whether C++11's `thread_local` storage duration specifier is
233 // supported.
234 #ifdef ABSL_HAVE_THREAD_LOCAL
235 #error ABSL_HAVE_THREAD_LOCAL cannot be directly set
236 #elif defined(__APPLE__)
237 // Notes:
238 // * Xcode's clang did not support `thread_local` until version 8, and
239 //   even then not for all iOS < 9.0.
240 // * Xcode 9.3 started disallowing `thread_local` for 32-bit iOS simulator
241 //   targeting iOS 9.x.
242 // * Xcode 10 moves the deployment target check for iOS < 9.0 to link time
243 //   making ABSL_HAVE_FEATURE unreliable there.
244 //
245 #if ABSL_HAVE_FEATURE(cxx_thread_local) && \
246     !(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
247 #define ABSL_HAVE_THREAD_LOCAL 1
248 #endif
249 #else  // !defined(__APPLE__)
250 #define ABSL_HAVE_THREAD_LOCAL 1
251 #endif
252 
253 // There are platforms for which TLS should not be used even though the compiler
254 // makes it seem like it's supported (Android NDK < r12b for example).
255 // This is primarily because of linker problems and toolchain misconfiguration:
256 // Abseil does not intend to support this indefinitely. Currently, the newest
257 // toolchain that we intend to support that requires this behavior is the
258 // r11 NDK - allowing for a 5 year support window on that means this option
259 // is likely to be removed around June of 2021.
260 // TLS isn't supported until NDK r12b per
261 // https://developer.android.com/ndk/downloads/revision_history.html
262 // Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
263 // <android/ndk-version.h>. For NDK < r16, users should define these macros,
264 // e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11.
265 #if defined(__ANDROID__) && defined(__clang__)
266 #if __has_include(<android/ndk-version.h>)
267 #include <android/ndk-version.h>
268 #endif  // __has_include(<android/ndk-version.h>)
269 #if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \
270     defined(__NDK_MINOR__) &&                                               \
271     ((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))
272 #undef ABSL_HAVE_TLS
273 #undef ABSL_HAVE_THREAD_LOCAL
274 #endif
275 #endif  // defined(__ANDROID__) && defined(__clang__)
276 
277 // ABSL_HAVE_INTRINSIC_INT128
278 //
279 // Checks whether the __int128 compiler extension for a 128-bit integral type is
280 // supported.
281 //
282 // Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is
283 // supported, but we avoid using it in certain cases:
284 // * On Clang:
285 //   * Building using Clang for Windows, where the Clang runtime library has
286 //     128-bit support only on LP64 architectures, but Windows is LLP64.
287 // * On Nvidia's nvcc:
288 //   * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions
289 //     actually support __int128.
290 #ifdef ABSL_HAVE_INTRINSIC_INT128
291 #error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set
292 #elif defined(__SIZEOF_INT128__)
293 #if (defined(__clang__) && !defined(_WIN32)) || \
294     (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) ||                \
295     (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__))
296 #define ABSL_HAVE_INTRINSIC_INT128 1
297 #elif defined(__CUDACC__)
298 // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
299 // string explaining that it has been removed starting with CUDA 9. We use
300 // nested #ifs because there is no short-circuiting in the preprocessor.
301 // NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
302 #if __CUDACC_VER__ >= 70000
303 #define ABSL_HAVE_INTRINSIC_INT128 1
304 #endif  // __CUDACC_VER__ >= 70000
305 #endif  // defined(__CUDACC__)
306 #endif  // ABSL_HAVE_INTRINSIC_INT128
307 
308 // ABSL_HAVE_EXCEPTIONS
309 //
310 // Checks whether the compiler both supports and enables exceptions. Many
311 // compilers support a "no exceptions" mode that disables exceptions.
312 //
313 // Generally, when ABSL_HAVE_EXCEPTIONS is not defined:
314 //
315 // * Code using `throw` and `try` may not compile.
316 // * The `noexcept` specifier will still compile and behave as normal.
317 // * The `noexcept` operator may still return `false`.
318 //
319 // For further details, consult the compiler's documentation.
320 #ifdef ABSL_HAVE_EXCEPTIONS
321 #error ABSL_HAVE_EXCEPTIONS cannot be directly set.
322 
323 #elif defined(__clang__)
324 
325 #if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
326 // Clang >= 3.6
327 #if ABSL_HAVE_FEATURE(cxx_exceptions)
328 #define ABSL_HAVE_EXCEPTIONS 1
329 #endif  // ABSL_HAVE_FEATURE(cxx_exceptions)
330 #else
331 // Clang < 3.6
332 // http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
333 #if defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions)
334 #define ABSL_HAVE_EXCEPTIONS 1
335 #endif  // defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions)
336 #endif  // __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
337 
338 // Handle remaining special cases and default to exceptions being supported.
339 #elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) &&    \
340     !(defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__cpp_exceptions)) && \
341     !(defined(_MSC_VER) && !defined(_CPPUNWIND))
342 #define ABSL_HAVE_EXCEPTIONS 1
343 #endif
344 
345 // -----------------------------------------------------------------------------
346 // Platform Feature Checks
347 // -----------------------------------------------------------------------------
348 
349 // Currently supported operating systems and associated preprocessor
350 // symbols:
351 //
352 //   Linux and Linux-derived           __linux__
353 //   Android                           __ANDROID__ (implies __linux__)
354 //   Linux (non-Android)               __linux__ && !__ANDROID__
355 //   Darwin (macOS and iOS)            __APPLE__
356 //   Akaros (http://akaros.org)        __ros__
357 //   Windows                           _WIN32
358 //   NaCL                              __native_client__
359 //   AsmJS                             __asmjs__
360 //   WebAssembly                       __wasm__
361 //   Fuchsia                           __Fuchsia__
362 //
363 // Note that since Android defines both __ANDROID__ and __linux__, one
364 // may probe for either Linux or Android by simply testing for __linux__.
365 
366 // ABSL_HAVE_MMAP
367 //
368 // Checks whether the platform has an mmap(2) implementation as defined in
369 // POSIX.1-2001.
370 #ifdef ABSL_HAVE_MMAP
371 #error ABSL_HAVE_MMAP cannot be directly set
372 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) ||   \
373     defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
374     defined(__wasm__) || defined(__Fuchsia__) || defined(__sun) || \
375     defined(__ASYLO__) || defined(__myriad2__)
376 #define ABSL_HAVE_MMAP 1
377 #endif
378 
379 // ABSL_HAVE_PTHREAD_GETSCHEDPARAM
380 //
381 // Checks whether the platform implements the pthread_(get|set)schedparam(3)
382 // functions as defined in POSIX.1-2001.
383 #ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM
384 #error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
385 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
386     defined(__ros__)
387 #define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
388 #endif
389 
390 // ABSL_HAVE_SCHED_GETCPU
391 //
392 // Checks whether sched_getcpu is available.
393 #ifdef ABSL_HAVE_SCHED_GETCPU
394 #error ABSL_HAVE_SCHED_GETCPU cannot be directly set
395 #elif defined(__linux__)
396 #define ABSL_HAVE_SCHED_GETCPU 1
397 #endif
398 
399 // ABSL_HAVE_SCHED_YIELD
400 //
401 // Checks whether the platform implements sched_yield(2) as defined in
402 // POSIX.1-2001.
403 #ifdef ABSL_HAVE_SCHED_YIELD
404 #error ABSL_HAVE_SCHED_YIELD cannot be directly set
405 #elif defined(__linux__) || defined(__ros__) || defined(__native_client__)
406 #define ABSL_HAVE_SCHED_YIELD 1
407 #endif
408 
409 // ABSL_HAVE_SEMAPHORE_H
410 //
411 // Checks whether the platform supports the <semaphore.h> header and sem_init(3)
412 // family of functions as standardized in POSIX.1-2001.
413 //
414 // Note: While Apple provides <semaphore.h> for both iOS and macOS, it is
415 // explicitly deprecated and will cause build failures if enabled for those
416 // platforms.  We side-step the issue by not defining it here for Apple
417 // platforms.
418 #ifdef ABSL_HAVE_SEMAPHORE_H
419 #error ABSL_HAVE_SEMAPHORE_H cannot be directly set
420 #elif defined(__linux__) || defined(__ros__)
421 #define ABSL_HAVE_SEMAPHORE_H 1
422 #endif
423 
424 // ABSL_HAVE_ALARM
425 //
426 // Checks whether the platform supports the <signal.h> header and alarm(2)
427 // function as standardized in POSIX.1-2001.
428 #ifdef ABSL_HAVE_ALARM
429 #error ABSL_HAVE_ALARM cannot be directly set
430 #elif defined(__GOOGLE_GRTE_VERSION__)
431 // feature tests for Google's GRTE
432 #define ABSL_HAVE_ALARM 1
433 #elif defined(__GLIBC__)
434 // feature test for glibc
435 #define ABSL_HAVE_ALARM 1
436 #elif defined(_MSC_VER)
437 // feature tests for Microsoft's library
438 #elif defined(__MINGW32__)
439 // mingw32 doesn't provide alarm(2):
440 // https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.2-trunk/mingwrt/include/unistd.h
441 // mingw-w64 provides a no-op implementation:
442 // https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/alarm.c
443 #elif defined(__EMSCRIPTEN__)
444 // emscripten doesn't support signals
445 #elif defined(__Fuchsia__)
446 // Signals don't exist on fuchsia.
447 #elif defined(__native_client__)
448 #else
449 // other standard libraries
450 #define ABSL_HAVE_ALARM 1
451 #endif
452 
453 // ABSL_IS_LITTLE_ENDIAN
454 // ABSL_IS_BIG_ENDIAN
455 //
456 // Checks the endianness of the platform.
457 //
458 // Notes: uses the built in endian macros provided by GCC (since 4.6) and
459 // Clang (since 3.2); see
460 // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html.
461 // Otherwise, if _WIN32, assume little endian. Otherwise, bail with an error.
462 #if defined(ABSL_IS_BIG_ENDIAN)
463 #error "ABSL_IS_BIG_ENDIAN cannot be directly set."
464 #endif
465 #if defined(ABSL_IS_LITTLE_ENDIAN)
466 #error "ABSL_IS_LITTLE_ENDIAN cannot be directly set."
467 #endif
468 
469 #if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
470      __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
471 #define ABSL_IS_LITTLE_ENDIAN 1
472 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
473     __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
474 #define ABSL_IS_BIG_ENDIAN 1
475 #elif defined(_WIN32)
476 #define ABSL_IS_LITTLE_ENDIAN 1
477 #else
478 #error "absl endian detection needs to be set up for your compiler"
479 #endif
480 
481 // macOS 10.13 and iOS 10.11 don't let you use <any>, <optional>, or <variant>
482 // even though the headers exist and are publicly noted to work.  See
483 // https://github.com/abseil/abseil-cpp/issues/207 and
484 // https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
485 // libc++ spells out the availability requirements in the file
486 // llvm-project/libcxx/include/__config via the #define
487 // _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS.
488 #if defined(__APPLE__) && defined(_LIBCPP_VERSION) && \
489   ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
490    __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101400) || \
491   (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
492    __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 120000) || \
493   (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
494    __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 50000) || \
495   (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && \
496    __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 120000))
497 #define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 1
498 #else
499 #define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 0
500 #endif
501 
502 // ABSL_HAVE_STD_ANY
503 //
504 // Checks whether C++17 std::any is available by checking whether <any> exists.
505 #ifdef ABSL_HAVE_STD_ANY
506 #error "ABSL_HAVE_STD_ANY cannot be directly set."
507 #endif
508 
509 #ifdef __has_include
510 #if __has_include(<any>) && defined(__cplusplus) && __cplusplus >= 201703L && \
511     !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
512 #define ABSL_HAVE_STD_ANY 1
513 #endif
514 #endif
515 
516 // ABSL_HAVE_STD_OPTIONAL
517 //
518 // Checks whether C++17 std::optional is available.
519 #ifdef ABSL_HAVE_STD_OPTIONAL
520 #error "ABSL_HAVE_STD_OPTIONAL cannot be directly set."
521 #endif
522 
523 #ifdef __has_include
524 #if __has_include(<optional>) && defined(__cplusplus) && \
525     __cplusplus >= 201703L && !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
526 #define ABSL_HAVE_STD_OPTIONAL 1
527 #endif
528 #endif
529 
530 // ABSL_HAVE_STD_VARIANT
531 //
532 // Checks whether C++17 std::variant is available.
533 #ifdef ABSL_HAVE_STD_VARIANT
534 #error "ABSL_HAVE_STD_VARIANT cannot be directly set."
535 #endif
536 
537 #ifdef __has_include
538 #if __has_include(<variant>) && defined(__cplusplus) && \
539     __cplusplus >= 201703L && !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
540 #define ABSL_HAVE_STD_VARIANT 1
541 #endif
542 #endif
543 
544 // ABSL_HAVE_STD_STRING_VIEW
545 //
546 // Checks whether C++17 std::string_view is available.
547 #ifdef ABSL_HAVE_STD_STRING_VIEW
548 #error "ABSL_HAVE_STD_STRING_VIEW cannot be directly set."
549 #endif
550 
551 #ifdef __has_include
552 #if __has_include(<string_view>) && defined(__cplusplus) && \
553     __cplusplus >= 201703L
554 #define ABSL_HAVE_STD_STRING_VIEW 1
555 #endif
556 #endif
557 
558 // For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than
559 // the support for <optional>, <any>, <string_view>, <variant>. So we use
560 // _MSC_VER to check whether we have VS 2017 RTM (when <optional>, <any>,
561 // <string_view>, <variant> is implemented) or higher. Also, `__cplusplus` is
562 // not correctly set by MSVC, so we use `_MSVC_LANG` to check the language
563 // version.
564 // TODO(zhangxy): fix tests before enabling aliasing for `std::any`.
565 #if defined(_MSC_VER) && _MSC_VER >= 1910 &&         \
566     ((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || \
567      (defined(__cplusplus) && __cplusplus > 201402))
568 // #define ABSL_HAVE_STD_ANY 1
569 #define ABSL_HAVE_STD_OPTIONAL 1
570 #define ABSL_HAVE_STD_VARIANT 1
571 #define ABSL_HAVE_STD_STRING_VIEW 1
572 #endif
573 
574 // ABSL_USES_STD_ANY
575 //
576 // Indicates whether absl::any is an alias for std::any.
577 #if !defined(ABSL_OPTION_USE_STD_ANY)
578 #error options.h is misconfigured.
579 #elif ABSL_OPTION_USE_STD_ANY == 0 || \
580     (ABSL_OPTION_USE_STD_ANY == 2 && !defined(ABSL_HAVE_STD_ANY))
581 #undef ABSL_USES_STD_ANY
582 #elif ABSL_OPTION_USE_STD_ANY == 1 || \
583     (ABSL_OPTION_USE_STD_ANY == 2 && defined(ABSL_HAVE_STD_ANY))
584 #define ABSL_USES_STD_ANY 1
585 #else
586 #error options.h is misconfigured.
587 #endif
588 
589 // ABSL_USES_STD_OPTIONAL
590 //
591 // Indicates whether absl::optional is an alias for std::optional.
592 #if !defined(ABSL_OPTION_USE_STD_OPTIONAL)
593 #error options.h is misconfigured.
594 #elif ABSL_OPTION_USE_STD_OPTIONAL == 0 || \
595     (ABSL_OPTION_USE_STD_OPTIONAL == 2 && !defined(ABSL_HAVE_STD_OPTIONAL))
596 #undef ABSL_USES_STD_OPTIONAL
597 #elif ABSL_OPTION_USE_STD_OPTIONAL == 1 || \
598     (ABSL_OPTION_USE_STD_OPTIONAL == 2 && defined(ABSL_HAVE_STD_OPTIONAL))
599 #define ABSL_USES_STD_OPTIONAL 1
600 #else
601 #error options.h is misconfigured.
602 #endif
603 
604 // ABSL_USES_STD_VARIANT
605 //
606 // Indicates whether absl::variant is an alias for std::variant.
607 #if !defined(ABSL_OPTION_USE_STD_VARIANT)
608 #error options.h is misconfigured.
609 #elif ABSL_OPTION_USE_STD_VARIANT == 0 || \
610     (ABSL_OPTION_USE_STD_VARIANT == 2 && !defined(ABSL_HAVE_STD_VARIANT))
611 #undef ABSL_USES_STD_VARIANT
612 #elif ABSL_OPTION_USE_STD_VARIANT == 1 || \
613     (ABSL_OPTION_USE_STD_VARIANT == 2 && defined(ABSL_HAVE_STD_VARIANT))
614 #define ABSL_USES_STD_VARIANT 1
615 #else
616 #error options.h is misconfigured.
617 #endif
618 
619 // ABSL_USES_STD_STRING_VIEW
620 //
621 // Indicates whether absl::string_view is an alias for std::string_view.
622 #if !defined(ABSL_OPTION_USE_STD_STRING_VIEW)
623 #error options.h is misconfigured.
624 #elif ABSL_OPTION_USE_STD_STRING_VIEW == 0 || \
625     (ABSL_OPTION_USE_STD_STRING_VIEW == 2 &&  \
626      !defined(ABSL_HAVE_STD_STRING_VIEW))
627 #undef ABSL_USES_STD_STRING_VIEW
628 #elif ABSL_OPTION_USE_STD_STRING_VIEW == 1 || \
629     (ABSL_OPTION_USE_STD_STRING_VIEW == 2 &&  \
630      defined(ABSL_HAVE_STD_STRING_VIEW))
631 #define ABSL_USES_STD_STRING_VIEW 1
632 #else
633 #error options.h is misconfigured.
634 #endif
635 
636 // In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
637 // SEH exception from emplace for variant<SomeStruct> when constructing the
638 // struct can throw. This defeats some of variant_test and
639 // variant_exception_safety_test.
640 #if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG)
641 #define ABSL_INTERNAL_MSVC_2017_DBG_MODE
642 #endif
643 
644 // ABSL_INTERNAL_MANGLED_NS
645 // ABSL_INTERNAL_MANGLED_BACKREFERENCE
646 //
647 // Internal macros for building up mangled names in our internal fork of CCTZ.
648 // This implementation detail is only needed and provided for the MSVC build.
649 //
650 // These macros both expand to string literals.  ABSL_INTERNAL_MANGLED_NS is
651 // the mangled spelling of the `absl` namespace, and
652 // ABSL_INTERNAL_MANGLED_BACKREFERENCE is a back-reference integer representing
653 // the proper count to skip past the CCTZ fork namespace names.  (This number
654 // is one larger when there is an inline namespace name to skip.)
655 #if defined(_MSC_VER)
656 #if ABSL_OPTION_USE_INLINE_NAMESPACE == 0
657 #define ABSL_INTERNAL_MANGLED_NS "absl"
658 #define ABSL_INTERNAL_MANGLED_BACKREFERENCE "5"
659 #else
660 #define ABSL_INTERNAL_MANGLED_NS \
661   ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME) "@absl"
662 #define ABSL_INTERNAL_MANGLED_BACKREFERENCE "6"
663 #endif
664 #endif
665 
666 #undef ABSL_INTERNAL_HAS_KEYWORD
667 
668 // ABSL_DLL
669 //
670 // When building Abseil as a DLL, this macro expands to `__declspec(dllexport)`
671 // so we can annotate symbols appropriately as being exported. When used in
672 // headers consuming a DLL, this macro expands to `__declspec(dllimport)` so
673 // that consumers know the symbol is defined inside the DLL. In all other cases,
674 // the macro expands to nothing.
675 #if defined(_MSC_VER)
676 #if defined(ABSL_BUILD_DLL)
677 #define ABSL_DLL __declspec(dllexport)
678 #elif defined(ABSL_CONSUME_DLL)
679 #define ABSL_DLL __declspec(dllimport)
680 #else
681 #define ABSL_DLL
682 #endif
683 #else
684 #define ABSL_DLL
685 #endif  // defined(_MSC_VER)
686 
687 // ABSL_HAVE_MEMORY_SANITIZER
688 //
689 // MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
690 // a compiler instrumentation module and a run-time library.
691 #ifdef ABSL_HAVE_MEMORY_SANITIZER
692 #error "ABSL_HAVE_MEMORY_SANITIZER cannot be directly set."
693 #elif defined(MEMORY_SANITIZER)
694 // The MEMORY_SANITIZER macro is deprecated but we will continue to honor it
695 // for now.
696 #define ABSL_HAVE_MEMORY_SANITIZER 1
697 #elif defined(__SANITIZE_MEMORY__)
698 #define ABSL_HAVE_MEMORY_SANITIZER 1
699 #elif !defined(__native_client__) && ABSL_HAVE_FEATURE(memory_sanitizer)
700 #define ABSL_HAVE_MEMORY_SANITIZER 1
701 #endif
702 
703 // ABSL_HAVE_THREAD_SANITIZER
704 //
705 // ThreadSanitizer (TSan) is a fast data race detector.
706 #ifdef ABSL_HAVE_THREAD_SANITIZER
707 #error "ABSL_HAVE_THREAD_SANITIZER cannot be directly set."
708 #elif defined(THREAD_SANITIZER)
709 // The THREAD_SANITIZER macro is deprecated but we will continue to honor it
710 // for now.
711 #define ABSL_HAVE_THREAD_SANITIZER 1
712 #elif defined(__SANITIZE_THREAD__)
713 #define ABSL_HAVE_THREAD_SANITIZER 1
714 #elif ABSL_HAVE_FEATURE(thread_sanitizer)
715 #define ABSL_HAVE_THREAD_SANITIZER 1
716 #endif
717 
718 // ABSL_HAVE_ADDRESS_SANITIZER
719 //
720 // AddressSanitizer (ASan) is a fast memory error detector.
721 #ifdef ABSL_HAVE_ADDRESS_SANITIZER
722 #error "ABSL_HAVE_ADDRESS_SANITIZER cannot be directly set."
723 #elif defined(ADDRESS_SANITIZER)
724 // The ADDRESS_SANITIZER macro is deprecated but we will continue to honor it
725 // for now.
726 #define ABSL_HAVE_ADDRESS_SANITIZER 1
727 #elif defined(__SANITIZE_ADDRESS__)
728 #define ABSL_HAVE_ADDRESS_SANITIZER 1
729 #elif ABSL_HAVE_FEATURE(address_sanitizer)
730 #define ABSL_HAVE_ADDRESS_SANITIZER 1
731 #endif
732 
733 // ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
734 //
735 // Class template argument deduction is a language feature added in C++17.
736 #ifdef ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
737 #error "ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION cannot be directly set."
738 #elif defined(__cpp_deduction_guides)
739 #define ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1
740 #endif
741 
742 #endif  // ABSL_BASE_CONFIG_H_
743