Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:40:42

0001 // Copyright 2017 The Abseil Authors.
0002 //
0003 // Licensed under the Apache License, Version 2.0 (the "License");
0004 // you may not use this file except in compliance with the License.
0005 // You may obtain a copy of the License at
0006 //
0007 //      https://www.apache.org/licenses/LICENSE-2.0
0008 //
0009 // Unless required by applicable law or agreed to in writing, software
0010 // distributed under the License is distributed on an "AS IS" BASIS,
0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0012 // See the License for the specific language governing permissions and
0013 // limitations under the License.
0014 //
0015 // This header file defines macros for declaring attributes for functions,
0016 // types, and variables.
0017 //
0018 // These macros are used within Abseil and allow the compiler to optimize, where
0019 // applicable, certain function calls.
0020 //
0021 // Most macros here are exposing GCC or Clang features, and are stubbed out for
0022 // other compilers.
0023 //
0024 // GCC attributes documentation:
0025 //   https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html
0026 //   https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Variable-Attributes.html
0027 //   https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Type-Attributes.html
0028 //
0029 // Most attributes in this file are already supported by GCC 4.7. However, some
0030 // of them are not supported in older version of Clang. Thus, we check
0031 // `__has_attribute()` first. If the check fails, we check if we are on GCC and
0032 // assume the attribute exists on GCC (which is verified on GCC 4.7).
0033 
0034 #ifndef ABSL_BASE_ATTRIBUTES_H_
0035 #define ABSL_BASE_ATTRIBUTES_H_
0036 
0037 #include "absl/base/config.h"
0038 
0039 // ABSL_HAVE_ATTRIBUTE
0040 //
0041 // A function-like feature checking macro that is a wrapper around
0042 // `__has_attribute`, which is defined by GCC 5+ and Clang and evaluates to a
0043 // nonzero constant integer if the attribute is supported or 0 if not.
0044 //
0045 // It evaluates to zero if `__has_attribute` is not defined by the compiler.
0046 //
0047 // GCC: https://gcc.gnu.org/gcc-5/changes.html
0048 // Clang: https://clang.llvm.org/docs/LanguageExtensions.html
0049 #ifdef __has_attribute
0050 #define ABSL_HAVE_ATTRIBUTE(x) __has_attribute(x)
0051 #else
0052 #define ABSL_HAVE_ATTRIBUTE(x) 0
0053 #endif
0054 
0055 // ABSL_HAVE_CPP_ATTRIBUTE
0056 //
0057 // A function-like feature checking macro that accepts C++11 style attributes.
0058 // It's a wrapper around `__has_cpp_attribute`, defined by ISO C++ SD-6
0059 // (https://en.cppreference.com/w/cpp/experimental/feature_test). If we don't
0060 // find `__has_cpp_attribute`, will evaluate to 0.
0061 #if defined(__cplusplus) && defined(__has_cpp_attribute)
0062 // NOTE: requiring __cplusplus above should not be necessary, but
0063 // works around https://bugs.llvm.org/show_bug.cgi?id=23435.
0064 #define ABSL_HAVE_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
0065 #else
0066 #define ABSL_HAVE_CPP_ATTRIBUTE(x) 0
0067 #endif
0068 
0069 // -----------------------------------------------------------------------------
0070 // Function Attributes
0071 // -----------------------------------------------------------------------------
0072 //
0073 // GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
0074 // Clang: https://clang.llvm.org/docs/AttributeReference.html
0075 
0076 // ABSL_PRINTF_ATTRIBUTE
0077 // ABSL_SCANF_ATTRIBUTE
0078 //
0079 // Tells the compiler to perform `printf` format string checking if the
0080 // compiler supports it; see the 'format' attribute in
0081 // <https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html>.
0082 //
0083 // Note: As the GCC manual states, "[s]ince non-static C++ methods
0084 // have an implicit 'this' argument, the arguments of such methods
0085 // should be counted from two, not one."
0086 #if ABSL_HAVE_ATTRIBUTE(format) || (defined(__GNUC__) && !defined(__clang__))
0087 #define ABSL_PRINTF_ATTRIBUTE(string_index, first_to_check) \
0088   __attribute__((__format__(__printf__, string_index, first_to_check)))
0089 #define ABSL_SCANF_ATTRIBUTE(string_index, first_to_check) \
0090   __attribute__((__format__(__scanf__, string_index, first_to_check)))
0091 #else
0092 #define ABSL_PRINTF_ATTRIBUTE(string_index, first_to_check)
0093 #define ABSL_SCANF_ATTRIBUTE(string_index, first_to_check)
0094 #endif
0095 
0096 // ABSL_ATTRIBUTE_ALWAYS_INLINE
0097 // ABSL_ATTRIBUTE_NOINLINE
0098 //
0099 // Forces functions to either inline or not inline. Introduced in gcc 3.1.
0100 #if ABSL_HAVE_ATTRIBUTE(always_inline) || \
0101     (defined(__GNUC__) && !defined(__clang__))
0102 #define ABSL_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
0103 #define ABSL_HAVE_ATTRIBUTE_ALWAYS_INLINE 1
0104 #else
0105 #define ABSL_ATTRIBUTE_ALWAYS_INLINE
0106 #endif
0107 
0108 #if ABSL_HAVE_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__))
0109 #define ABSL_ATTRIBUTE_NOINLINE __attribute__((noinline))
0110 #define ABSL_HAVE_ATTRIBUTE_NOINLINE 1
0111 #else
0112 #define ABSL_ATTRIBUTE_NOINLINE
0113 #endif
0114 
0115 // ABSL_ATTRIBUTE_NO_TAIL_CALL
0116 //
0117 // Prevents the compiler from optimizing away stack frames for functions which
0118 // end in a call to another function.
0119 #if ABSL_HAVE_ATTRIBUTE(disable_tail_calls)
0120 #define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 1
0121 #define ABSL_ATTRIBUTE_NO_TAIL_CALL __attribute__((disable_tail_calls))
0122 #elif defined(__GNUC__) && !defined(__clang__) && !defined(__e2k__)
0123 #define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 1
0124 #define ABSL_ATTRIBUTE_NO_TAIL_CALL \
0125   __attribute__((optimize("no-optimize-sibling-calls")))
0126 #else
0127 #define ABSL_ATTRIBUTE_NO_TAIL_CALL
0128 #define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 0
0129 #endif
0130 
0131 // ABSL_ATTRIBUTE_WEAK
0132 //
0133 // Tags a function as weak for the purposes of compilation and linking.
0134 // Weak attributes did not work properly in LLVM's Windows backend before
0135 // 9.0.0, so disable them there. See https://bugs.llvm.org/show_bug.cgi?id=37598
0136 // for further information.
0137 // The MinGW compiler doesn't complain about the weak attribute until the link
0138 // step, presumably because Windows doesn't use ELF binaries.
0139 #if (ABSL_HAVE_ATTRIBUTE(weak) ||                                         \
0140      (defined(__GNUC__) && !defined(__clang__))) &&                       \
0141     (!defined(_WIN32) || (defined(__clang__) && __clang_major__ >= 9)) && \
0142     !defined(__MINGW32__)
0143 #undef ABSL_ATTRIBUTE_WEAK
0144 #define ABSL_ATTRIBUTE_WEAK __attribute__((weak))
0145 #define ABSL_HAVE_ATTRIBUTE_WEAK 1
0146 #else
0147 #define ABSL_ATTRIBUTE_WEAK
0148 #define ABSL_HAVE_ATTRIBUTE_WEAK 0
0149 #endif
0150 
0151 // ABSL_ATTRIBUTE_NONNULL
0152 //
0153 // Tells the compiler either (a) that a particular function parameter
0154 // should be a non-null pointer, or (b) that all pointer arguments should
0155 // be non-null.
0156 //
0157 // Note: As the GCC manual states, "[s]ince non-static C++ methods
0158 // have an implicit 'this' argument, the arguments of such methods
0159 // should be counted from two, not one."
0160 //
0161 // Args are indexed starting at 1.
0162 //
0163 // For non-static class member functions, the implicit `this` argument
0164 // is arg 1, and the first explicit argument is arg 2. For static class member
0165 // functions, there is no implicit `this`, and the first explicit argument is
0166 // arg 1.
0167 //
0168 // Example:
0169 //
0170 //   /* arg_a cannot be null, but arg_b can */
0171 //   void Function(void* arg_a, void* arg_b) ABSL_ATTRIBUTE_NONNULL(1);
0172 //
0173 //   class C {
0174 //     /* arg_a cannot be null, but arg_b can */
0175 //     void Method(void* arg_a, void* arg_b) ABSL_ATTRIBUTE_NONNULL(2);
0176 //
0177 //     /* arg_a cannot be null, but arg_b can */
0178 //     static void StaticMethod(void* arg_a, void* arg_b)
0179 //     ABSL_ATTRIBUTE_NONNULL(1);
0180 //   };
0181 //
0182 // If no arguments are provided, then all pointer arguments should be non-null.
0183 //
0184 //  /* No pointer arguments may be null. */
0185 //  void Function(void* arg_a, void* arg_b, int arg_c) ABSL_ATTRIBUTE_NONNULL();
0186 //
0187 // NOTE: The GCC nonnull attribute actually accepts a list of arguments, but
0188 // ABSL_ATTRIBUTE_NONNULL does not.
0189 #if ABSL_HAVE_ATTRIBUTE(nonnull) || (defined(__GNUC__) && !defined(__clang__))
0190 #define ABSL_ATTRIBUTE_NONNULL(arg_index) __attribute__((nonnull(arg_index)))
0191 #else
0192 #define ABSL_ATTRIBUTE_NONNULL(...)
0193 #endif
0194 
0195 // ABSL_ATTRIBUTE_NORETURN
0196 //
0197 // Tells the compiler that a given function never returns.
0198 //
0199 // Deprecated: Prefer the `[[noreturn]]` attribute standardized by C++11 over
0200 // this macro.
0201 #if ABSL_HAVE_ATTRIBUTE(noreturn) || (defined(__GNUC__) && !defined(__clang__))
0202 #define ABSL_ATTRIBUTE_NORETURN __attribute__((noreturn))
0203 #elif defined(_MSC_VER)
0204 #define ABSL_ATTRIBUTE_NORETURN __declspec(noreturn)
0205 #else
0206 #define ABSL_ATTRIBUTE_NORETURN
0207 #endif
0208 
0209 // ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS
0210 //
0211 // Tells the AddressSanitizer (or other memory testing tools) to ignore a given
0212 // function. Useful for cases when a function reads random locations on stack,
0213 // calls _exit from a cloned subprocess, deliberately accesses buffer
0214 // out of bounds or does other scary things with memory.
0215 // NOTE: GCC supports AddressSanitizer(asan) since 4.8.
0216 // https://gcc.gnu.org/gcc-4.8/changes.html
0217 #if defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
0218     ABSL_HAVE_ATTRIBUTE(no_sanitize_address)
0219 #define ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
0220 #elif defined(ABSL_HAVE_ADDRESS_SANITIZER) && defined(_MSC_VER) && \
0221     _MSC_VER >= 1928
0222 // https://docs.microsoft.com/en-us/cpp/cpp/no-sanitize-address
0223 #define ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS __declspec(no_sanitize_address)
0224 #elif defined(ABSL_HAVE_HWADDRESS_SANITIZER) && ABSL_HAVE_ATTRIBUTE(no_sanitize)
0225 // HWAddressSanitizer is a sanitizer similar to AddressSanitizer, which uses CPU
0226 // features to detect similar bugs with less CPU and memory overhead.
0227 // NOTE: GCC supports HWAddressSanitizer(hwasan) since 11.
0228 // https://gcc.gnu.org/gcc-11/changes.html
0229 #define ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS \
0230   __attribute__((no_sanitize("hwaddress")))
0231 #else
0232 #define ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS
0233 #endif
0234 
0235 // ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY
0236 //
0237 // Tells the MemorySanitizer to relax the handling of a given function. All "Use
0238 // of uninitialized value" warnings from such functions will be suppressed, and
0239 // all values loaded from memory will be considered fully initialized.  This
0240 // attribute is similar to the ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS attribute
0241 // above, but deals with initialized-ness rather than addressability issues.
0242 // NOTE: MemorySanitizer(msan) is supported by Clang but not GCC.
0243 #if ABSL_HAVE_ATTRIBUTE(no_sanitize_memory)
0244 #define ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
0245 #else
0246 #define ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY
0247 #endif
0248 
0249 // ABSL_ATTRIBUTE_NO_SANITIZE_THREAD
0250 //
0251 // Tells the ThreadSanitizer to not instrument a given function.
0252 // NOTE: GCC supports ThreadSanitizer(tsan) since 4.8.
0253 // https://gcc.gnu.org/gcc-4.8/changes.html
0254 #if ABSL_HAVE_ATTRIBUTE(no_sanitize_thread)
0255 #define ABSL_ATTRIBUTE_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
0256 #else
0257 #define ABSL_ATTRIBUTE_NO_SANITIZE_THREAD
0258 #endif
0259 
0260 // ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED
0261 //
0262 // Tells the UndefinedSanitizer to ignore a given function. Useful for cases
0263 // where certain behavior (eg. division by zero) is being used intentionally.
0264 // NOTE: GCC supports UndefinedBehaviorSanitizer(ubsan) since 4.9.
0265 // https://gcc.gnu.org/gcc-4.9/changes.html
0266 #if ABSL_HAVE_ATTRIBUTE(no_sanitize_undefined)
0267 #define ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED \
0268   __attribute__((no_sanitize_undefined))
0269 #elif ABSL_HAVE_ATTRIBUTE(no_sanitize)
0270 #define ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED \
0271   __attribute__((no_sanitize("undefined")))
0272 #else
0273 #define ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED
0274 #endif
0275 
0276 // ABSL_ATTRIBUTE_NO_SANITIZE_CFI
0277 //
0278 // Tells the ControlFlowIntegrity sanitizer to not instrument a given function.
0279 // See https://clang.llvm.org/docs/ControlFlowIntegrity.html for details.
0280 #if ABSL_HAVE_ATTRIBUTE(no_sanitize) && defined(__llvm__)
0281 #define ABSL_ATTRIBUTE_NO_SANITIZE_CFI __attribute__((no_sanitize("cfi")))
0282 #else
0283 #define ABSL_ATTRIBUTE_NO_SANITIZE_CFI
0284 #endif
0285 
0286 // ABSL_ATTRIBUTE_NO_SANITIZE_SAFESTACK
0287 //
0288 // Tells the SafeStack to not instrument a given function.
0289 // See https://clang.llvm.org/docs/SafeStack.html for details.
0290 #if ABSL_HAVE_ATTRIBUTE(no_sanitize)
0291 #define ABSL_ATTRIBUTE_NO_SANITIZE_SAFESTACK \
0292   __attribute__((no_sanitize("safe-stack")))
0293 #else
0294 #define ABSL_ATTRIBUTE_NO_SANITIZE_SAFESTACK
0295 #endif
0296 
0297 // ABSL_ATTRIBUTE_RETURNS_NONNULL
0298 //
0299 // Tells the compiler that a particular function never returns a null pointer.
0300 #if ABSL_HAVE_ATTRIBUTE(returns_nonnull)
0301 #define ABSL_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
0302 #else
0303 #define ABSL_ATTRIBUTE_RETURNS_NONNULL
0304 #endif
0305 
0306 // ABSL_HAVE_ATTRIBUTE_SECTION
0307 //
0308 // Indicates whether labeled sections are supported. Weak symbol support is
0309 // a prerequisite. Labeled sections are not supported on Darwin/iOS.
0310 #ifdef ABSL_HAVE_ATTRIBUTE_SECTION
0311 #error ABSL_HAVE_ATTRIBUTE_SECTION cannot be directly set
0312 #elif (ABSL_HAVE_ATTRIBUTE(section) ||                \
0313        (defined(__GNUC__) && !defined(__clang__))) && \
0314     !defined(__APPLE__) && ABSL_HAVE_ATTRIBUTE_WEAK
0315 #define ABSL_HAVE_ATTRIBUTE_SECTION 1
0316 
0317 // ABSL_ATTRIBUTE_SECTION
0318 //
0319 // Tells the compiler/linker to put a given function into a section and define
0320 // `__start_ ## name` and `__stop_ ## name` symbols to bracket the section.
0321 // This functionality is supported by GNU linker.  Any function annotated with
0322 // `ABSL_ATTRIBUTE_SECTION` must not be inlined, or it will be placed into
0323 // whatever section its caller is placed into.
0324 //
0325 #ifndef ABSL_ATTRIBUTE_SECTION
0326 #define ABSL_ATTRIBUTE_SECTION(name) \
0327   __attribute__((section(#name))) __attribute__((noinline))
0328 #endif
0329 
0330 // ABSL_ATTRIBUTE_SECTION_VARIABLE
0331 //
0332 // Tells the compiler/linker to put a given variable into a section and define
0333 // `__start_ ## name` and `__stop_ ## name` symbols to bracket the section.
0334 // This functionality is supported by GNU linker.
0335 #ifndef ABSL_ATTRIBUTE_SECTION_VARIABLE
0336 #ifdef _AIX
0337 // __attribute__((section(#name))) on AIX is achieved by using the `.csect`
0338 // psudo op which includes an additional integer as part of its syntax indcating
0339 // alignment. If data fall under different alignments then you might get a
0340 // compilation error indicating a `Section type conflict`.
0341 #define ABSL_ATTRIBUTE_SECTION_VARIABLE(name)
0342 #else
0343 #define ABSL_ATTRIBUTE_SECTION_VARIABLE(name) __attribute__((section(#name)))
0344 #endif
0345 #endif
0346 
0347 // ABSL_DECLARE_ATTRIBUTE_SECTION_VARS
0348 //
0349 // A weak section declaration to be used as a global declaration
0350 // for ABSL_ATTRIBUTE_SECTION_START|STOP(name) to compile and link
0351 // even without functions with ABSL_ATTRIBUTE_SECTION(name).
0352 // ABSL_DEFINE_ATTRIBUTE_SECTION should be in the exactly one file; it's
0353 // a no-op on ELF but not on Mach-O.
0354 //
0355 #ifndef ABSL_DECLARE_ATTRIBUTE_SECTION_VARS
0356 #define ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(name)   \
0357   extern char __start_##name[] ABSL_ATTRIBUTE_WEAK; \
0358   extern char __stop_##name[] ABSL_ATTRIBUTE_WEAK
0359 #endif
0360 #ifndef ABSL_DEFINE_ATTRIBUTE_SECTION_VARS
0361 #define ABSL_INIT_ATTRIBUTE_SECTION_VARS(name)
0362 #define ABSL_DEFINE_ATTRIBUTE_SECTION_VARS(name)
0363 #endif
0364 
0365 // ABSL_ATTRIBUTE_SECTION_START
0366 //
0367 // Returns `void*` pointers to start/end of a section of code with
0368 // functions having ABSL_ATTRIBUTE_SECTION(name).
0369 // Returns 0 if no such functions exist.
0370 // One must ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(name) for this to compile and
0371 // link.
0372 //
0373 #define ABSL_ATTRIBUTE_SECTION_START(name) \
0374   (reinterpret_cast<void *>(__start_##name))
0375 #define ABSL_ATTRIBUTE_SECTION_STOP(name) \
0376   (reinterpret_cast<void *>(__stop_##name))
0377 
0378 #else  // !ABSL_HAVE_ATTRIBUTE_SECTION
0379 
0380 #define ABSL_HAVE_ATTRIBUTE_SECTION 0
0381 
0382 // provide dummy definitions
0383 #define ABSL_ATTRIBUTE_SECTION(name)
0384 #define ABSL_ATTRIBUTE_SECTION_VARIABLE(name)
0385 #define ABSL_INIT_ATTRIBUTE_SECTION_VARS(name)
0386 #define ABSL_DEFINE_ATTRIBUTE_SECTION_VARS(name)
0387 #define ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(name)
0388 #define ABSL_ATTRIBUTE_SECTION_START(name) (reinterpret_cast<void *>(0))
0389 #define ABSL_ATTRIBUTE_SECTION_STOP(name) (reinterpret_cast<void *>(0))
0390 
0391 #endif  // ABSL_ATTRIBUTE_SECTION
0392 
0393 // ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
0394 //
0395 // Support for aligning the stack on 32-bit x86.
0396 #if ABSL_HAVE_ATTRIBUTE(force_align_arg_pointer) || \
0397     (defined(__GNUC__) && !defined(__clang__))
0398 #if defined(__i386__)
0399 #define ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC \
0400   __attribute__((force_align_arg_pointer))
0401 #define ABSL_REQUIRE_STACK_ALIGN_TRAMPOLINE (0)
0402 #elif defined(__x86_64__)
0403 #define ABSL_REQUIRE_STACK_ALIGN_TRAMPOLINE (1)
0404 #define ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
0405 #else  // !__i386__ && !__x86_64
0406 #define ABSL_REQUIRE_STACK_ALIGN_TRAMPOLINE (0)
0407 #define ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
0408 #endif  // __i386__
0409 #else
0410 #define ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
0411 #define ABSL_REQUIRE_STACK_ALIGN_TRAMPOLINE (0)
0412 #endif
0413 
0414 // ABSL_MUST_USE_RESULT
0415 //
0416 // Tells the compiler to warn about unused results.
0417 //
0418 // For code or headers that are assured to only build with C++17 and up, prefer
0419 // just using the standard `[[nodiscard]]` directly over this macro.
0420 //
0421 // When annotating a function, it must appear as the first part of the
0422 // declaration or definition. The compiler will warn if the return value from
0423 // such a function is unused:
0424 //
0425 //   ABSL_MUST_USE_RESULT Sprocket* AllocateSprocket();
0426 //   AllocateSprocket();  // Triggers a warning.
0427 //
0428 // When annotating a class, it is equivalent to annotating every function which
0429 // returns an instance.
0430 //
0431 //   class ABSL_MUST_USE_RESULT Sprocket {};
0432 //   Sprocket();  // Triggers a warning.
0433 //
0434 //   Sprocket MakeSprocket();
0435 //   MakeSprocket();  // Triggers a warning.
0436 //
0437 // Note that references and pointers are not instances:
0438 //
0439 //   Sprocket* SprocketPointer();
0440 //   SprocketPointer();  // Does *not* trigger a warning.
0441 //
0442 // ABSL_MUST_USE_RESULT allows using cast-to-void to suppress the unused result
0443 // warning. For that, warn_unused_result is used only for clang but not for gcc.
0444 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425
0445 //
0446 // Note: past advice was to place the macro after the argument list.
0447 //
0448 // TODO(b/176172494): Use ABSL_HAVE_CPP_ATTRIBUTE(nodiscard) when all code is
0449 // compliant with the stricter [[nodiscard]].
0450 #if defined(__clang__) && ABSL_HAVE_ATTRIBUTE(warn_unused_result)
0451 #define ABSL_MUST_USE_RESULT __attribute__((warn_unused_result))
0452 #else
0453 #define ABSL_MUST_USE_RESULT
0454 #endif
0455 
0456 // ABSL_ATTRIBUTE_HOT, ABSL_ATTRIBUTE_COLD
0457 //
0458 // Tells GCC that a function is hot or cold. GCC can use this information to
0459 // improve static analysis, i.e. a conditional branch to a cold function
0460 // is likely to be not-taken.
0461 // This annotation is used for function declarations.
0462 //
0463 // Example:
0464 //
0465 //   int foo() ABSL_ATTRIBUTE_HOT;
0466 #if ABSL_HAVE_ATTRIBUTE(hot) || (defined(__GNUC__) && !defined(__clang__))
0467 #define ABSL_ATTRIBUTE_HOT __attribute__((hot))
0468 #else
0469 #define ABSL_ATTRIBUTE_HOT
0470 #endif
0471 
0472 #if ABSL_HAVE_ATTRIBUTE(cold) || (defined(__GNUC__) && !defined(__clang__))
0473 #define ABSL_ATTRIBUTE_COLD __attribute__((cold))
0474 #else
0475 #define ABSL_ATTRIBUTE_COLD
0476 #endif
0477 
0478 // ABSL_XRAY_ALWAYS_INSTRUMENT, ABSL_XRAY_NEVER_INSTRUMENT, ABSL_XRAY_LOG_ARGS
0479 //
0480 // We define the ABSL_XRAY_ALWAYS_INSTRUMENT and ABSL_XRAY_NEVER_INSTRUMENT
0481 // macro used as an attribute to mark functions that must always or never be
0482 // instrumented by XRay. Currently, this is only supported in Clang/LLVM.
0483 //
0484 // For reference on the LLVM XRay instrumentation, see
0485 // http://llvm.org/docs/XRay.html.
0486 //
0487 // A function with the XRAY_ALWAYS_INSTRUMENT macro attribute in its declaration
0488 // will always get the XRay instrumentation sleds. These sleds may introduce
0489 // some binary size and runtime overhead and must be used sparingly.
0490 //
0491 // These attributes only take effect when the following conditions are met:
0492 //
0493 //   * The file/target is built in at least C++11 mode, with a Clang compiler
0494 //     that supports XRay attributes.
0495 //   * The file/target is built with the -fxray-instrument flag set for the
0496 //     Clang/LLVM compiler.
0497 //   * The function is defined in the translation unit (the compiler honors the
0498 //     attribute in either the definition or the declaration, and must match).
0499 //
0500 // There are cases when, even when building with XRay instrumentation, users
0501 // might want to control specifically which functions are instrumented for a
0502 // particular build using special-case lists provided to the compiler. These
0503 // special case lists are provided to Clang via the
0504 // -fxray-always-instrument=... and -fxray-never-instrument=... flags. The
0505 // attributes in source take precedence over these special-case lists.
0506 //
0507 // To disable the XRay attributes at build-time, users may define
0508 // ABSL_NO_XRAY_ATTRIBUTES. Do NOT define ABSL_NO_XRAY_ATTRIBUTES on specific
0509 // packages/targets, as this may lead to conflicting definitions of functions at
0510 // link-time.
0511 //
0512 // XRay isn't currently supported on Android:
0513 // https://github.com/android/ndk/issues/368
0514 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::xray_always_instrument) && \
0515     !defined(ABSL_NO_XRAY_ATTRIBUTES) && !defined(__ANDROID__)
0516 #define ABSL_XRAY_ALWAYS_INSTRUMENT [[clang::xray_always_instrument]]
0517 #define ABSL_XRAY_NEVER_INSTRUMENT [[clang::xray_never_instrument]]
0518 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::xray_log_args)
0519 #define ABSL_XRAY_LOG_ARGS(N) \
0520   [[clang::xray_always_instrument, clang::xray_log_args(N)]]
0521 #else
0522 #define ABSL_XRAY_LOG_ARGS(N) [[clang::xray_always_instrument]]
0523 #endif
0524 #else
0525 #define ABSL_XRAY_ALWAYS_INSTRUMENT
0526 #define ABSL_XRAY_NEVER_INSTRUMENT
0527 #define ABSL_XRAY_LOG_ARGS(N)
0528 #endif
0529 
0530 // ABSL_ATTRIBUTE_REINITIALIZES
0531 //
0532 // Indicates that a member function reinitializes the entire object to a known
0533 // state, independent of the previous state of the object.
0534 //
0535 // The clang-tidy check bugprone-use-after-move allows member functions marked
0536 // with this attribute to be called on objects that have been moved from;
0537 // without the attribute, this would result in a use-after-move warning.
0538 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::reinitializes)
0539 #define ABSL_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
0540 #else
0541 #define ABSL_ATTRIBUTE_REINITIALIZES
0542 #endif
0543 
0544 // -----------------------------------------------------------------------------
0545 // Variable Attributes
0546 // -----------------------------------------------------------------------------
0547 
0548 // ABSL_ATTRIBUTE_UNUSED
0549 //
0550 // Prevents the compiler from complaining about variables that appear unused.
0551 //
0552 // For code or headers that are assured to only build with C++17 and up, prefer
0553 // just using the standard '[[maybe_unused]]' directly over this macro.
0554 //
0555 // Due to differences in positioning requirements between the old, compiler
0556 // specific __attribute__ syntax and the now standard [[maybe_unused]], this
0557 // macro does not attempt to take advantage of '[[maybe_unused]]'.
0558 #if ABSL_HAVE_ATTRIBUTE(unused) || (defined(__GNUC__) && !defined(__clang__))
0559 #undef ABSL_ATTRIBUTE_UNUSED
0560 #define ABSL_ATTRIBUTE_UNUSED __attribute__((__unused__))
0561 #else
0562 #define ABSL_ATTRIBUTE_UNUSED
0563 #endif
0564 
0565 // ABSL_ATTRIBUTE_INITIAL_EXEC
0566 //
0567 // Tells the compiler to use "initial-exec" mode for a thread-local variable.
0568 // See http://people.redhat.com/drepper/tls.pdf for the gory details.
0569 #if ABSL_HAVE_ATTRIBUTE(tls_model) || (defined(__GNUC__) && !defined(__clang__))
0570 #define ABSL_ATTRIBUTE_INITIAL_EXEC __attribute__((tls_model("initial-exec")))
0571 #else
0572 #define ABSL_ATTRIBUTE_INITIAL_EXEC
0573 #endif
0574 
0575 // ABSL_ATTRIBUTE_PACKED
0576 //
0577 // Instructs the compiler not to use natural alignment for a tagged data
0578 // structure, but instead to reduce its alignment to 1.
0579 //
0580 // Therefore, DO NOT APPLY THIS ATTRIBUTE TO STRUCTS CONTAINING ATOMICS. Doing
0581 // so can cause atomic variables to be mis-aligned and silently violate
0582 // atomicity on x86.
0583 //
0584 // This attribute can either be applied to members of a structure or to a
0585 // structure in its entirety. Applying this attribute (judiciously) to a
0586 // structure in its entirety to optimize the memory footprint of very
0587 // commonly-used structs is fine. Do not apply this attribute to a structure in
0588 // its entirety if the purpose is to control the offsets of the members in the
0589 // structure. Instead, apply this attribute only to structure members that need
0590 // it.
0591 //
0592 // When applying ABSL_ATTRIBUTE_PACKED only to specific structure members the
0593 // natural alignment of structure members not annotated is preserved. Aligned
0594 // member accesses are faster than non-aligned member accesses even if the
0595 // targeted microprocessor supports non-aligned accesses.
0596 #if ABSL_HAVE_ATTRIBUTE(packed) || (defined(__GNUC__) && !defined(__clang__))
0597 #define ABSL_ATTRIBUTE_PACKED __attribute__((__packed__))
0598 #else
0599 #define ABSL_ATTRIBUTE_PACKED
0600 #endif
0601 
0602 // ABSL_ATTRIBUTE_FUNC_ALIGN
0603 //
0604 // Tells the compiler to align the function start at least to certain
0605 // alignment boundary
0606 #if ABSL_HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))
0607 #define ABSL_ATTRIBUTE_FUNC_ALIGN(bytes) __attribute__((aligned(bytes)))
0608 #else
0609 #define ABSL_ATTRIBUTE_FUNC_ALIGN(bytes)
0610 #endif
0611 
0612 // ABSL_FALLTHROUGH_INTENDED
0613 //
0614 // Annotates implicit fall-through between switch labels, allowing a case to
0615 // indicate intentional fallthrough and turn off warnings about any lack of a
0616 // `break` statement. The ABSL_FALLTHROUGH_INTENDED macro should be followed by
0617 // a semicolon and can be used in most places where `break` can, provided that
0618 // no statements exist between it and the next switch label.
0619 //
0620 // Example:
0621 //
0622 //  switch (x) {
0623 //    case 40:
0624 //    case 41:
0625 //      if (truth_is_out_there) {
0626 //        ++x;
0627 //        ABSL_FALLTHROUGH_INTENDED;  // Use instead of/along with annotations
0628 //                                    // in comments
0629 //      } else {
0630 //        return x;
0631 //      }
0632 //    case 42:
0633 //      ...
0634 //
0635 // Notes: When supported, GCC and Clang can issue a warning on switch labels
0636 // with unannotated fallthrough using the warning `-Wimplicit-fallthrough`. See
0637 // clang documentation on language extensions for details:
0638 // https://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
0639 //
0640 // When used with unsupported compilers, the ABSL_FALLTHROUGH_INTENDED macro has
0641 // no effect on diagnostics. In any case this macro has no effect on runtime
0642 // behavior and performance of code.
0643 
0644 #ifdef ABSL_FALLTHROUGH_INTENDED
0645 #error "ABSL_FALLTHROUGH_INTENDED should not be defined."
0646 #elif ABSL_HAVE_CPP_ATTRIBUTE(fallthrough)
0647 #define ABSL_FALLTHROUGH_INTENDED [[fallthrough]]
0648 #elif ABSL_HAVE_CPP_ATTRIBUTE(clang::fallthrough)
0649 #define ABSL_FALLTHROUGH_INTENDED [[clang::fallthrough]]
0650 #elif ABSL_HAVE_CPP_ATTRIBUTE(gnu::fallthrough)
0651 #define ABSL_FALLTHROUGH_INTENDED [[gnu::fallthrough]]
0652 #else
0653 #define ABSL_FALLTHROUGH_INTENDED \
0654   do {                            \
0655   } while (0)
0656 #endif
0657 
0658 // ABSL_DEPRECATED()
0659 //
0660 // Marks a deprecated class, struct, enum, function, method and variable
0661 // declarations. The macro argument is used as a custom diagnostic message (e.g.
0662 // suggestion of a better alternative).
0663 //
0664 // For code or headers that are assured to only build with C++14 and up, prefer
0665 // just using the standard `[[deprecated("message")]]` directly over this macro.
0666 //
0667 // Examples:
0668 //
0669 //   class ABSL_DEPRECATED("Use Bar instead") Foo {...};
0670 //
0671 //   ABSL_DEPRECATED("Use Baz() instead") void Bar() {...}
0672 //
0673 //   template <typename T>
0674 //   ABSL_DEPRECATED("Use DoThat() instead")
0675 //   void DoThis();
0676 //
0677 //   enum FooEnum {
0678 //     kBar ABSL_DEPRECATED("Use kBaz instead"),
0679 //   };
0680 //
0681 // Every usage of a deprecated entity will trigger a warning when compiled with
0682 // GCC/Clang's `-Wdeprecated-declarations` option. Google's production toolchain
0683 // turns this warning off by default, instead relying on clang-tidy to report
0684 // new uses of deprecated code.
0685 #if ABSL_HAVE_ATTRIBUTE(deprecated)
0686 #define ABSL_DEPRECATED(message) __attribute__((deprecated(message)))
0687 #else
0688 #define ABSL_DEPRECATED(message)
0689 #endif
0690 
0691 // When deprecating Abseil code, it is sometimes necessary to turn off the
0692 // warning within Abseil, until the deprecated code is actually removed. The
0693 // deprecated code can be surrounded with these directives to achieve that
0694 // result.
0695 //
0696 // class ABSL_DEPRECATED("Use Bar instead") Foo;
0697 //
0698 // ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
0699 // Baz ComputeBazFromFoo(Foo f);
0700 // ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING
0701 #if defined(__GNUC__) || defined(__clang__)
0702 // Clang also supports these GCC pragmas.
0703 #define ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING \
0704   _Pragma("GCC diagnostic push")             \
0705   _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
0706 #define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING \
0707   _Pragma("GCC diagnostic pop")
0708 #elif defined(_MSC_VER)
0709 #define ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING \
0710   _Pragma("warning(push)") _Pragma("warning(disable: 4996)")
0711 #define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING \
0712   _Pragma("warning(pop)")
0713 #else
0714 #define ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
0715 #define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING
0716 #endif  // defined(__GNUC__) || defined(__clang__)
0717 
0718 // ABSL_CONST_INIT
0719 //
0720 // A variable declaration annotated with the `ABSL_CONST_INIT` attribute will
0721 // not compile (on supported platforms) unless the variable has a constant
0722 // initializer. This is useful for variables with static and thread storage
0723 // duration, because it guarantees that they will not suffer from the so-called
0724 // "static init order fiasco".
0725 //
0726 // This attribute must be placed on the initializing declaration of the
0727 // variable. Some compilers will give a -Wmissing-constinit warning when this
0728 // attribute is placed on some other declaration but missing from the
0729 // initializing declaration.
0730 //
0731 // In some cases (notably with thread_local variables), `ABSL_CONST_INIT` can
0732 // also be used in a non-initializing declaration to tell the compiler that a
0733 // variable is already initialized, reducing overhead that would otherwise be
0734 // incurred by a hidden guard variable. Thus annotating all declarations with
0735 // this attribute is recommended to potentially enhance optimization.
0736 //
0737 // Example:
0738 //
0739 //   class MyClass {
0740 //    public:
0741 //     ABSL_CONST_INIT static MyType my_var;
0742 //   };
0743 //
0744 //   ABSL_CONST_INIT MyType MyClass::my_var = MakeMyType(...);
0745 //
0746 // For code or headers that are assured to only build with C++20 and up, prefer
0747 // just using the standard `constinit` keyword directly over this macro.
0748 //
0749 // Note that this attribute is redundant if the variable is declared constexpr.
0750 #if defined(__cpp_constinit) && __cpp_constinit >= 201907L
0751 #define ABSL_CONST_INIT constinit
0752 #elif ABSL_HAVE_CPP_ATTRIBUTE(clang::require_constant_initialization)
0753 #define ABSL_CONST_INIT [[clang::require_constant_initialization]]
0754 #else
0755 #define ABSL_CONST_INIT
0756 #endif
0757 
0758 // ABSL_ATTRIBUTE_PURE_FUNCTION
0759 //
0760 // ABSL_ATTRIBUTE_PURE_FUNCTION is used to annotate declarations of "pure"
0761 // functions. A function is pure if its return value is only a function of its
0762 // arguments. The pure attribute prohibits a function from modifying the state
0763 // of the program that is observable by means other than inspecting the
0764 // function's return value. Declaring such functions with the pure attribute
0765 // allows the compiler to avoid emitting some calls in repeated invocations of
0766 // the function with the same argument values.
0767 //
0768 // Example:
0769 //
0770 //  ABSL_ATTRIBUTE_PURE_FUNCTION std::string FormatTime(Time t);
0771 #if ABSL_HAVE_CPP_ATTRIBUTE(gnu::pure)
0772 #define ABSL_ATTRIBUTE_PURE_FUNCTION [[gnu::pure]]
0773 #elif ABSL_HAVE_ATTRIBUTE(pure)
0774 #define ABSL_ATTRIBUTE_PURE_FUNCTION __attribute__((pure))
0775 #else
0776 // If the attribute isn't defined, we'll fallback to ABSL_MUST_USE_RESULT since
0777 // pure functions are useless if its return is ignored.
0778 #define ABSL_ATTRIBUTE_PURE_FUNCTION ABSL_MUST_USE_RESULT
0779 #endif
0780 
0781 // ABSL_ATTRIBUTE_CONST_FUNCTION
0782 //
0783 // ABSL_ATTRIBUTE_CONST_FUNCTION is used to annotate declarations of "const"
0784 // functions. A const function is similar to a pure function, with one
0785 // exception: Pure functions may return value that depend on a non-volatile
0786 // object that isn't provided as a function argument, while the const function
0787 // is guaranteed to return the same result given the same arguments.
0788 //
0789 // Example:
0790 //
0791 //  ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Milliseconds(Duration d);
0792 #if defined(_MSC_VER) && !defined(__clang__)
0793 // Put the MSVC case first since MSVC seems to parse const as a C++ keyword.
0794 #define ABSL_ATTRIBUTE_CONST_FUNCTION ABSL_ATTRIBUTE_PURE_FUNCTION
0795 #elif ABSL_HAVE_CPP_ATTRIBUTE(gnu::const)
0796 #define ABSL_ATTRIBUTE_CONST_FUNCTION [[gnu::const]]
0797 #elif ABSL_HAVE_ATTRIBUTE(const)
0798 #define ABSL_ATTRIBUTE_CONST_FUNCTION __attribute__((const))
0799 #else
0800 // Since const functions are more restrictive pure function, we'll fallback to a
0801 // pure function if the const attribute is not handled.
0802 #define ABSL_ATTRIBUTE_CONST_FUNCTION ABSL_ATTRIBUTE_PURE_FUNCTION
0803 #endif
0804 
0805 // ABSL_ATTRIBUTE_LIFETIME_BOUND indicates that a resource owned by a function
0806 // parameter or implicit object parameter is retained by the return value of the
0807 // annotated function (or, for a parameter of a constructor, in the value of the
0808 // constructed object). This attribute causes warnings to be produced if a
0809 // temporary object does not live long enough.
0810 //
0811 // When applied to a reference parameter, the referenced object is assumed to be
0812 // retained by the return value of the function. When applied to a non-reference
0813 // parameter (for example, a pointer or a class type), all temporaries
0814 // referenced by the parameter are assumed to be retained by the return value of
0815 // the function.
0816 //
0817 // See also the upstream documentation:
0818 // https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
0819 // https://learn.microsoft.com/en-us/cpp/code-quality/c26816?view=msvc-170
0820 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::lifetimebound)
0821 #define ABSL_ATTRIBUTE_LIFETIME_BOUND [[clang::lifetimebound]]
0822 #elif ABSL_HAVE_CPP_ATTRIBUTE(msvc::lifetimebound)
0823 #define ABSL_ATTRIBUTE_LIFETIME_BOUND [[msvc::lifetimebound]]
0824 #elif ABSL_HAVE_ATTRIBUTE(lifetimebound)
0825 #define ABSL_ATTRIBUTE_LIFETIME_BOUND __attribute__((lifetimebound))
0826 #else
0827 #define ABSL_ATTRIBUTE_LIFETIME_BOUND
0828 #endif
0829 
0830 // ABSL_INTERNAL_ATTRIBUTE_VIEW indicates that a type acts like a view i.e. a
0831 // raw (non-owning) pointer. This enables diagnoses similar to those enabled by
0832 // ABSL_ATTRIBUTE_LIFETIME_BOUND.
0833 //
0834 // See the following links for details:
0835 // https://reviews.llvm.org/D64448
0836 // https://lists.llvm.org/pipermail/cfe-dev/2018-November/060355.html
0837 #if ABSL_HAVE_CPP_ATTRIBUTE(gsl::Pointer)
0838 #define ABSL_INTERNAL_ATTRIBUTE_VIEW [[gsl::Pointer]]
0839 #else
0840 #define ABSL_INTERNAL_ATTRIBUTE_VIEW
0841 #endif
0842 
0843 // ABSL_INTERNAL_ATTRIBUTE_OWNER indicates that a type acts like a smart
0844 // (owning) pointer. This enables diagnoses similar to those enabled by
0845 // ABSL_ATTRIBUTE_LIFETIME_BOUND.
0846 //
0847 // See the following links for details:
0848 // https://reviews.llvm.org/D64448
0849 // https://lists.llvm.org/pipermail/cfe-dev/2018-November/060355.html
0850 #if ABSL_HAVE_CPP_ATTRIBUTE(gsl::Owner)
0851 #define ABSL_INTERNAL_ATTRIBUTE_OWNER [[gsl::Owner]]
0852 #else
0853 #define ABSL_INTERNAL_ATTRIBUTE_OWNER
0854 #endif
0855 
0856 // ABSL_ATTRIBUTE_TRIVIAL_ABI
0857 // Indicates that a type is "trivially relocatable" -- meaning it can be
0858 // relocated without invoking the constructor/destructor, using a form of move
0859 // elision.
0860 //
0861 // From a memory safety point of view, putting aside destructor ordering, it's
0862 // safe to apply ABSL_ATTRIBUTE_TRIVIAL_ABI if an object's location
0863 // can change over the course of its lifetime: if a constructor can be run one
0864 // place, and then the object magically teleports to another place where some
0865 // methods are run, and then the object teleports to yet another place where it
0866 // is destroyed. This is notably not true for self-referential types, where the
0867 // move-constructor must keep the self-reference up to date. If the type changed
0868 // location without invoking the move constructor, it would have a dangling
0869 // self-reference.
0870 //
0871 // The use of this teleporting machinery means that the number of paired
0872 // move/destroy operations can change, and so it is a bad idea to apply this to
0873 // a type meant to count the number of moves.
0874 //
0875 // Warning: applying this can, rarely, break callers. Objects passed by value
0876 // will be destroyed at the end of the call, instead of the end of the
0877 // full-expression containing the call. In addition, it changes the ABI
0878 // of functions accepting this type by value (e.g. to pass in registers).
0879 //
0880 // See also the upstream documentation:
0881 // https://clang.llvm.org/docs/AttributeReference.html#trivial-abi
0882 //
0883 // b/321691395 - This is currently disabled in open-source builds since
0884 // compiler support differs. If system libraries compiled with GCC are mixed
0885 // with libraries compiled with Clang, types will have different ideas about
0886 // their ABI, leading to hard to debug crashes.
0887 #define ABSL_ATTRIBUTE_TRIVIAL_ABI
0888 
0889 // ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS
0890 //
0891 // Indicates a data member can be optimized to occupy no space (if it is empty)
0892 // and/or its tail padding can be used for other members.
0893 //
0894 // For code that is assured to only build with C++20 or later, prefer using
0895 // the standard attribute `[[no_unique_address]]` directly instead of this
0896 // macro.
0897 //
0898 // https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/#c20-no_unique_address
0899 // Current versions of MSVC have disabled `[[no_unique_address]]` since it
0900 // breaks ABI compatibility, but offers `[[msvc::no_unique_address]]` for
0901 // situations when it can be assured that it is desired. Since Abseil does not
0902 // claim ABI compatibility in mixed builds, we can offer it unconditionally.
0903 #if defined(_MSC_VER) && _MSC_VER >= 1929
0904 #define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
0905 #elif ABSL_HAVE_CPP_ATTRIBUTE(no_unique_address)
0906 #define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS [[no_unique_address]]
0907 #else
0908 #define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS
0909 #endif
0910 
0911 // ABSL_ATTRIBUTE_UNINITIALIZED
0912 //
0913 // GCC and Clang support a flag `-ftrivial-auto-var-init=<option>` (<option>
0914 // can be "zero" or "pattern") that can be used to initialize automatic stack
0915 // variables. Variables with this attribute will be left uninitialized,
0916 // overriding the compiler flag.
0917 //
0918 // See https://clang.llvm.org/docs/AttributeReference.html#uninitialized
0919 // and https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-uninitialized-variable-attribute
0920 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::uninitialized)
0921 #define ABSL_ATTRIBUTE_UNINITIALIZED [[clang::uninitialized]]
0922 #elif ABSL_HAVE_CPP_ATTRIBUTE(gnu::uninitialized)
0923 #define ABSL_ATTRIBUTE_UNINITIALIZED [[gnu::uninitialized]]
0924 #elif ABSL_HAVE_ATTRIBUTE(uninitialized)
0925 #define ABSL_ATTRIBUTE_UNINITIALIZED __attribute__((uninitialized))
0926 #else
0927 #define ABSL_ATTRIBUTE_UNINITIALIZED
0928 #endif
0929 
0930 // ABSL_ATTRIBUTE_WARN_UNUSED
0931 //
0932 // Compilers routinely warn about trivial variables that are unused.  For
0933 // non-trivial types, this warning is suppressed since the
0934 // constructor/destructor may be intentional and load-bearing, for example, with
0935 // a RAII scoped lock.
0936 //
0937 // For example:
0938 //
0939 // class ABSL_ATTRIBUTE_WARN_UNUSED MyType {
0940 //  public:
0941 //   MyType();
0942 //   ~MyType();
0943 // };
0944 //
0945 // void foo() {
0946 //   // Warns with ABSL_ATTRIBUTE_WARN_UNUSED attribute present.
0947 //   MyType unused;
0948 // }
0949 //
0950 // See https://clang.llvm.org/docs/AttributeReference.html#warn-unused and
0951 // https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html#index-warn_005funused-type-attribute
0952 #if ABSL_HAVE_CPP_ATTRIBUTE(gnu::warn_unused)
0953 #define ABSL_ATTRIBUTE_WARN_UNUSED [[gnu::warn_unused]]
0954 #else
0955 #define ABSL_ATTRIBUTE_WARN_UNUSED
0956 #endif
0957 
0958 #endif  // ABSL_BASE_ATTRIBUTES_H_