1 // Copyright 2017 The Abseil Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // This header file defines macros for declaring attributes for functions, 16 // types, and variables. 17 // 18 // These macros are used within Abseil and allow the compiler to optimize, where 19 // applicable, certain function calls. 20 // 21 // Most macros here are exposing GCC or Clang features, and are stubbed out for 22 // other compilers. 23 // 24 // GCC attributes documentation: 25 // https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html 26 // https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Variable-Attributes.html 27 // https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Type-Attributes.html 28 // 29 // Most attributes in this file are already supported by GCC 4.7. However, some 30 // of them are not supported in older version of Clang. Thus, we check 31 // `__has_attribute()` first. If the check fails, we check if we are on GCC and 32 // assume the attribute exists on GCC (which is verified on GCC 4.7). 33 34 #ifndef ABSL_BASE_ATTRIBUTES_H_ 35 #define ABSL_BASE_ATTRIBUTES_H_ 36 37 #include "absl/base/config.h" 38 39 // ABSL_HAVE_ATTRIBUTE 40 // 41 // A function-like feature checking macro that is a wrapper around 42 // `__has_attribute`, which is defined by GCC 5+ and Clang and evaluates to a 43 // nonzero constant integer if the attribute is supported or 0 if not. 44 // 45 // It evaluates to zero if `__has_attribute` is not defined by the compiler. 46 // 47 // GCC: https://gcc.gnu.org/gcc-5/changes.html 48 // Clang: https://clang.llvm.org/docs/LanguageExtensions.html 49 #ifdef __has_attribute 50 #define ABSL_HAVE_ATTRIBUTE(x) __has_attribute(x) 51 #else 52 #define ABSL_HAVE_ATTRIBUTE(x) 0 53 #endif 54 55 // ABSL_HAVE_CPP_ATTRIBUTE 56 // 57 // A function-like feature checking macro that accepts C++11 style attributes. 58 // It's a wrapper around `__has_cpp_attribute`, defined by ISO C++ SD-6 59 // (https://en.cppreference.com/w/cpp/experimental/feature_test). If we don't 60 // find `__has_cpp_attribute`, will evaluate to 0. 61 #if defined(__cplusplus) && defined(__has_cpp_attribute) 62 // NOTE: requiring __cplusplus above should not be necessary, but 63 // works around https://bugs.llvm.org/show_bug.cgi?id=23435. 64 #define ABSL_HAVE_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) 65 #else 66 #define ABSL_HAVE_CPP_ATTRIBUTE(x) 0 67 #endif 68 69 // ----------------------------------------------------------------------------- 70 // Function Attributes 71 // ----------------------------------------------------------------------------- 72 // 73 // GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html 74 // Clang: https://clang.llvm.org/docs/AttributeReference.html 75 76 // ABSL_PRINTF_ATTRIBUTE 77 // ABSL_SCANF_ATTRIBUTE 78 // 79 // Tells the compiler to perform `printf` format string checking if the 80 // compiler supports it; see the 'format' attribute in 81 // <https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html>. 82 // 83 // Note: As the GCC manual states, "[s]ince non-static C++ methods 84 // have an implicit 'this' argument, the arguments of such methods 85 // should be counted from two, not one." 86 #if ABSL_HAVE_ATTRIBUTE(format) || (defined(__GNUC__) && !defined(__clang__)) 87 #define ABSL_PRINTF_ATTRIBUTE(string_index, first_to_check) \ 88 __attribute__((__format__(__printf__, string_index, first_to_check))) 89 #define ABSL_SCANF_ATTRIBUTE(string_index, first_to_check) \ 90 __attribute__((__format__(__scanf__, string_index, first_to_check))) 91 #else 92 #define ABSL_PRINTF_ATTRIBUTE(string_index, first_to_check) 93 #define ABSL_SCANF_ATTRIBUTE(string_index, first_to_check) 94 #endif 95 96 // ABSL_ATTRIBUTE_ALWAYS_INLINE 97 // ABSL_ATTRIBUTE_NOINLINE 98 // 99 // Forces functions to either inline or not inline. Introduced in gcc 3.1. 100 #if ABSL_HAVE_ATTRIBUTE(always_inline) || \ 101 (defined(__GNUC__) && !defined(__clang__)) 102 #define ABSL_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline)) 103 #define ABSL_HAVE_ATTRIBUTE_ALWAYS_INLINE 1 104 #else 105 #define ABSL_ATTRIBUTE_ALWAYS_INLINE 106 #endif 107 108 #if ABSL_HAVE_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__)) 109 #define ABSL_ATTRIBUTE_NOINLINE __attribute__((noinline)) 110 #define ABSL_HAVE_ATTRIBUTE_NOINLINE 1 111 #else 112 #define ABSL_ATTRIBUTE_NOINLINE 113 #endif 114 115 // ABSL_ATTRIBUTE_NO_TAIL_CALL 116 // 117 // Prevents the compiler from optimizing away stack frames for functions which 118 // end in a call to another function. 119 #if ABSL_HAVE_ATTRIBUTE(disable_tail_calls) 120 #define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 1 121 #define ABSL_ATTRIBUTE_NO_TAIL_CALL __attribute__((disable_tail_calls)) 122 #elif defined(__GNUC__) && !defined(__clang__) && !defined(__e2k__) 123 #define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 1 124 #define ABSL_ATTRIBUTE_NO_TAIL_CALL \ 125 __attribute__((optimize("no-optimize-sibling-calls"))) 126 #else 127 #define ABSL_ATTRIBUTE_NO_TAIL_CALL 128 #define ABSL_HAVE_ATTRIBUTE_NO_TAIL_CALL 0 129 #endif 130 131 // ABSL_ATTRIBUTE_WEAK 132 // 133 // Tags a function as weak for the purposes of compilation and linking. 134 // Weak attributes did not work properly in LLVM's Windows backend before 135 // 9.0.0, so disable them there. See https://bugs.llvm.org/show_bug.cgi?id=37598 136 // for further information. 137 // The MinGW compiler doesn't complain about the weak attribute until the link 138 // step, presumably because Windows doesn't use ELF binaries. 139 #if (ABSL_HAVE_ATTRIBUTE(weak) || \ 140 (defined(__GNUC__) && !defined(__clang__))) && \ 141 (!defined(_WIN32) || (defined(__clang__) && __clang_major__ >= 9)) && \ 142 !defined(__MINGW32__) 143 #undef ABSL_ATTRIBUTE_WEAK 144 #define ABSL_ATTRIBUTE_WEAK __attribute__((weak)) 145 #define ABSL_HAVE_ATTRIBUTE_WEAK 1 146 #else 147 #define ABSL_ATTRIBUTE_WEAK 148 #define ABSL_HAVE_ATTRIBUTE_WEAK 0 149 #endif 150 151 // ABSL_ATTRIBUTE_NONNULL 152 // 153 // Tells the compiler either (a) that a particular function parameter 154 // should be a non-null pointer, or (b) that all pointer arguments should 155 // be non-null. 156 // 157 // Note: As the GCC manual states, "[s]ince non-static C++ methods 158 // have an implicit 'this' argument, the arguments of such methods 159 // should be counted from two, not one." 160 // 161 // Args are indexed starting at 1. 162 // 163 // For non-static class member functions, the implicit `this` argument 164 // is arg 1, and the first explicit argument is arg 2. For static class member 165 // functions, there is no implicit `this`, and the first explicit argument is 166 // arg 1. 167 // 168 // Example: 169 // 170 // /* arg_a cannot be null, but arg_b can */ 171 // void Function(void* arg_a, void* arg_b) ABSL_ATTRIBUTE_NONNULL(1); 172 // 173 // class C { 174 // /* arg_a cannot be null, but arg_b can */ 175 // void Method(void* arg_a, void* arg_b) ABSL_ATTRIBUTE_NONNULL(2); 176 // 177 // /* arg_a cannot be null, but arg_b can */ 178 // static void StaticMethod(void* arg_a, void* arg_b) 179 // ABSL_ATTRIBUTE_NONNULL(1); 180 // }; 181 // 182 // If no arguments are provided, then all pointer arguments should be non-null. 183 // 184 // /* No pointer arguments may be null. */ 185 // void Function(void* arg_a, void* arg_b, int arg_c) ABSL_ATTRIBUTE_NONNULL(); 186 // 187 // NOTE: The GCC nonnull attribute actually accepts a list of arguments, but 188 // ABSL_ATTRIBUTE_NONNULL does not. 189 #if ABSL_HAVE_ATTRIBUTE(nonnull) || (defined(__GNUC__) && !defined(__clang__)) 190 #define ABSL_ATTRIBUTE_NONNULL(arg_index) __attribute__((nonnull(arg_index))) 191 #else 192 #define ABSL_ATTRIBUTE_NONNULL(...) 193 #endif 194 195 // ABSL_ATTRIBUTE_NORETURN 196 // 197 // Tells the compiler that a given function never returns. 198 // 199 // Deprecated: Prefer the `[[noreturn]]` attribute standardized by C++11 over 200 // this macro. 201 #if ABSL_HAVE_ATTRIBUTE(noreturn) || (defined(__GNUC__) && !defined(__clang__)) 202 #define ABSL_ATTRIBUTE_NORETURN __attribute__((noreturn)) 203 #elif defined(_MSC_VER) 204 #define ABSL_ATTRIBUTE_NORETURN __declspec(noreturn) 205 #else 206 #define ABSL_ATTRIBUTE_NORETURN 207 #endif 208 209 // ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS 210 // 211 // Tells the AddressSanitizer (or other memory testing tools) to ignore a given 212 // function. Useful for cases when a function reads random locations on stack, 213 // calls _exit from a cloned subprocess, deliberately accesses buffer 214 // out of bounds or does other scary things with memory. 215 // NOTE: GCC supports AddressSanitizer(asan) since 4.8. 216 // https://gcc.gnu.org/gcc-4.8/changes.html 217 #if defined(ABSL_HAVE_ADDRESS_SANITIZER) && \ 218 ABSL_HAVE_ATTRIBUTE(no_sanitize_address) 219 #define ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) 220 #elif defined(ABSL_HAVE_ADDRESS_SANITIZER) && defined(_MSC_VER) && \ 221 _MSC_VER >= 1928 222 // https://docs.microsoft.com/en-us/cpp/cpp/no-sanitize-address 223 #define ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS __declspec(no_sanitize_address) 224 #elif defined(ABSL_HAVE_HWADDRESS_SANITIZER) && ABSL_HAVE_ATTRIBUTE(no_sanitize) 225 // HWAddressSanitizer is a sanitizer similar to AddressSanitizer, which uses CPU 226 // features to detect similar bugs with less CPU and memory overhead. 227 // NOTE: GCC supports HWAddressSanitizer(hwasan) since 11. 228 // https://gcc.gnu.org/gcc-11/changes.html 229 #define ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS \ 230 __attribute__((no_sanitize("hwaddress"))) 231 #else 232 #define ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS 233 #endif 234 235 // ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY 236 // 237 // Tells the MemorySanitizer to relax the handling of a given function. All "Use 238 // of uninitialized value" warnings from such functions will be suppressed, and 239 // all values loaded from memory will be considered fully initialized. This 240 // attribute is similar to the ABSL_ATTRIBUTE_NO_SANITIZE_ADDRESS attribute 241 // above, but deals with initialized-ness rather than addressability issues. 242 // NOTE: MemorySanitizer(msan) is supported by Clang but not GCC. 243 #if ABSL_HAVE_ATTRIBUTE(no_sanitize_memory) 244 #define ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory)) 245 #else 246 #define ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY 247 #endif 248 249 // ABSL_ATTRIBUTE_NO_SANITIZE_THREAD 250 // 251 // Tells the ThreadSanitizer to not instrument a given function. 252 // NOTE: GCC supports ThreadSanitizer(tsan) since 4.8. 253 // https://gcc.gnu.org/gcc-4.8/changes.html 254 #if ABSL_HAVE_ATTRIBUTE(no_sanitize_thread) 255 #define ABSL_ATTRIBUTE_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread)) 256 #else 257 #define ABSL_ATTRIBUTE_NO_SANITIZE_THREAD 258 #endif 259 260 // ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED 261 // 262 // Tells the UndefinedSanitizer to ignore a given function. Useful for cases 263 // where certain behavior (eg. division by zero) is being used intentionally. 264 // NOTE: GCC supports UndefinedBehaviorSanitizer(ubsan) since 4.9. 265 // https://gcc.gnu.org/gcc-4.9/changes.html 266 #if ABSL_HAVE_ATTRIBUTE(no_sanitize_undefined) 267 #define ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED \ 268 __attribute__((no_sanitize_undefined)) 269 #elif ABSL_HAVE_ATTRIBUTE(no_sanitize) 270 #define ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED \ 271 __attribute__((no_sanitize("undefined"))) 272 #else 273 #define ABSL_ATTRIBUTE_NO_SANITIZE_UNDEFINED 274 #endif 275 276 // ABSL_ATTRIBUTE_NO_SANITIZE_CFI 277 // 278 // Tells the ControlFlowIntegrity sanitizer to not instrument a given function. 279 // See https://clang.llvm.org/docs/ControlFlowIntegrity.html for details. 280 #if ABSL_HAVE_ATTRIBUTE(no_sanitize) && defined(__llvm__) 281 #define ABSL_ATTRIBUTE_NO_SANITIZE_CFI __attribute__((no_sanitize("cfi"))) 282 #else 283 #define ABSL_ATTRIBUTE_NO_SANITIZE_CFI 284 #endif 285 286 // ABSL_ATTRIBUTE_NO_SANITIZE_SAFESTACK 287 // 288 // Tells the SafeStack to not instrument a given function. 289 // See https://clang.llvm.org/docs/SafeStack.html for details. 290 #if ABSL_HAVE_ATTRIBUTE(no_sanitize) 291 #define ABSL_ATTRIBUTE_NO_SANITIZE_SAFESTACK \ 292 __attribute__((no_sanitize("safe-stack"))) 293 #else 294 #define ABSL_ATTRIBUTE_NO_SANITIZE_SAFESTACK 295 #endif 296 297 // ABSL_ATTRIBUTE_RETURNS_NONNULL 298 // 299 // Tells the compiler that a particular function never returns a null pointer. 300 #if ABSL_HAVE_ATTRIBUTE(returns_nonnull) 301 #define ABSL_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) 302 #else 303 #define ABSL_ATTRIBUTE_RETURNS_NONNULL 304 #endif 305 306 // ABSL_HAVE_ATTRIBUTE_SECTION 307 // 308 // Indicates whether labeled sections are supported. Weak symbol support is 309 // a prerequisite. Labeled sections are not supported on Darwin/iOS. 310 #ifdef ABSL_HAVE_ATTRIBUTE_SECTION 311 #error ABSL_HAVE_ATTRIBUTE_SECTION cannot be directly set 312 #elif (ABSL_HAVE_ATTRIBUTE(section) || \ 313 (defined(__GNUC__) && !defined(__clang__))) && \ 314 !defined(__APPLE__) && ABSL_HAVE_ATTRIBUTE_WEAK 315 #define ABSL_HAVE_ATTRIBUTE_SECTION 1 316 317 // ABSL_ATTRIBUTE_SECTION 318 // 319 // Tells the compiler/linker to put a given function into a section and define 320 // `__start_ ## name` and `__stop_ ## name` symbols to bracket the section. 321 // This functionality is supported by GNU linker. Any function annotated with 322 // `ABSL_ATTRIBUTE_SECTION` must not be inlined, or it will be placed into 323 // whatever section its caller is placed into. 324 // 325 #ifndef ABSL_ATTRIBUTE_SECTION 326 #define ABSL_ATTRIBUTE_SECTION(name) \ 327 __attribute__((section(#name))) __attribute__((noinline)) 328 #endif 329 330 // ABSL_ATTRIBUTE_SECTION_VARIABLE 331 // 332 // Tells the compiler/linker to put a given variable into a section and define 333 // `__start_ ## name` and `__stop_ ## name` symbols to bracket the section. 334 // This functionality is supported by GNU linker. 335 #ifndef ABSL_ATTRIBUTE_SECTION_VARIABLE 336 #ifdef _AIX 337 // __attribute__((section(#name))) on AIX is achieved by using the `.csect` 338 // psudo op which includes an additional integer as part of its syntax indcating 339 // alignment. If data fall under different alignments then you might get a 340 // compilation error indicating a `Section type conflict`. 341 #define ABSL_ATTRIBUTE_SECTION_VARIABLE(name) 342 #else 343 #define ABSL_ATTRIBUTE_SECTION_VARIABLE(name) __attribute__((section(#name))) 344 #endif 345 #endif 346 347 // ABSL_DECLARE_ATTRIBUTE_SECTION_VARS 348 // 349 // A weak section declaration to be used as a global declaration 350 // for ABSL_ATTRIBUTE_SECTION_START|STOP(name) to compile and link 351 // even without functions with ABSL_ATTRIBUTE_SECTION(name). 352 // ABSL_DEFINE_ATTRIBUTE_SECTION should be in the exactly one file; it's 353 // a no-op on ELF but not on Mach-O. 354 // 355 #ifndef ABSL_DECLARE_ATTRIBUTE_SECTION_VARS 356 #define ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(name) \ 357 extern char __start_##name[] ABSL_ATTRIBUTE_WEAK; \ 358 extern char __stop_##name[] ABSL_ATTRIBUTE_WEAK 359 #endif 360 #ifndef ABSL_DEFINE_ATTRIBUTE_SECTION_VARS 361 #define ABSL_INIT_ATTRIBUTE_SECTION_VARS(name) 362 #define ABSL_DEFINE_ATTRIBUTE_SECTION_VARS(name) 363 #endif 364 365 // ABSL_ATTRIBUTE_SECTION_START 366 // 367 // Returns `void*` pointers to start/end of a section of code with 368 // functions having ABSL_ATTRIBUTE_SECTION(name). 369 // Returns 0 if no such functions exist. 370 // One must ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(name) for this to compile and 371 // link. 372 // 373 #define ABSL_ATTRIBUTE_SECTION_START(name) \ 374 (reinterpret_cast<void *>(__start_##name)) 375 #define ABSL_ATTRIBUTE_SECTION_STOP(name) \ 376 (reinterpret_cast<void *>(__stop_##name)) 377 378 #else // !ABSL_HAVE_ATTRIBUTE_SECTION 379 380 #define ABSL_HAVE_ATTRIBUTE_SECTION 0 381 382 // provide dummy definitions 383 #define ABSL_ATTRIBUTE_SECTION(name) 384 #define ABSL_ATTRIBUTE_SECTION_VARIABLE(name) 385 #define ABSL_INIT_ATTRIBUTE_SECTION_VARS(name) 386 #define ABSL_DEFINE_ATTRIBUTE_SECTION_VARS(name) 387 #define ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(name) 388 #define ABSL_ATTRIBUTE_SECTION_START(name) (reinterpret_cast<void *>(0)) 389 #define ABSL_ATTRIBUTE_SECTION_STOP(name) (reinterpret_cast<void *>(0)) 390 391 #endif // ABSL_ATTRIBUTE_SECTION 392 393 // ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC 394 // 395 // Support for aligning the stack on 32-bit x86. 396 #if ABSL_HAVE_ATTRIBUTE(force_align_arg_pointer) || \ 397 (defined(__GNUC__) && !defined(__clang__)) 398 #if defined(__i386__) 399 #define ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC \ 400 __attribute__((force_align_arg_pointer)) 401 #define ABSL_REQUIRE_STACK_ALIGN_TRAMPOLINE (0) 402 #elif defined(__x86_64__) 403 #define ABSL_REQUIRE_STACK_ALIGN_TRAMPOLINE (1) 404 #define ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC 405 #else // !__i386__ && !__x86_64 406 #define ABSL_REQUIRE_STACK_ALIGN_TRAMPOLINE (0) 407 #define ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC 408 #endif // __i386__ 409 #else 410 #define ABSL_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC 411 #define ABSL_REQUIRE_STACK_ALIGN_TRAMPOLINE (0) 412 #endif 413 414 // ABSL_MUST_USE_RESULT 415 // 416 // Tells the compiler to warn about unused results. 417 // 418 // For code or headers that are assured to only build with C++17 and up, prefer 419 // just using the standard `[[nodiscard]]` directly over this macro. 420 // 421 // When annotating a function, it must appear as the first part of the 422 // declaration or definition. The compiler will warn if the return value from 423 // such a function is unused: 424 // 425 // ABSL_MUST_USE_RESULT Sprocket* AllocateSprocket(); 426 // AllocateSprocket(); // Triggers a warning. 427 // 428 // When annotating a class, it is equivalent to annotating every function which 429 // returns an instance. 430 // 431 // class ABSL_MUST_USE_RESULT Sprocket {}; 432 // Sprocket(); // Triggers a warning. 433 // 434 // Sprocket MakeSprocket(); 435 // MakeSprocket(); // Triggers a warning. 436 // 437 // Note that references and pointers are not instances: 438 // 439 // Sprocket* SprocketPointer(); 440 // SprocketPointer(); // Does *not* trigger a warning. 441 // 442 // ABSL_MUST_USE_RESULT allows using cast-to-void to suppress the unused result 443 // warning. For that, warn_unused_result is used only for clang but not for gcc. 444 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 445 // 446 // Note: past advice was to place the macro after the argument list. 447 // 448 // TODO(b/176172494): Use ABSL_HAVE_CPP_ATTRIBUTE(nodiscard) when all code is 449 // compliant with the stricter [[nodiscard]]. 450 #if defined(__clang__) && ABSL_HAVE_ATTRIBUTE(warn_unused_result) 451 #define ABSL_MUST_USE_RESULT __attribute__((warn_unused_result)) 452 #else 453 #define ABSL_MUST_USE_RESULT 454 #endif 455 456 // ABSL_ATTRIBUTE_HOT, ABSL_ATTRIBUTE_COLD 457 // 458 // Tells GCC that a function is hot or cold. GCC can use this information to 459 // improve static analysis, i.e. a conditional branch to a cold function 460 // is likely to be not-taken. 461 // This annotation is used for function declarations. 462 // 463 // Example: 464 // 465 // int foo() ABSL_ATTRIBUTE_HOT; 466 #if ABSL_HAVE_ATTRIBUTE(hot) || (defined(__GNUC__) && !defined(__clang__)) 467 #define ABSL_ATTRIBUTE_HOT __attribute__((hot)) 468 #else 469 #define ABSL_ATTRIBUTE_HOT 470 #endif 471 472 #if ABSL_HAVE_ATTRIBUTE(cold) || (defined(__GNUC__) && !defined(__clang__)) 473 #define ABSL_ATTRIBUTE_COLD __attribute__((cold)) 474 #else 475 #define ABSL_ATTRIBUTE_COLD 476 #endif 477 478 // ABSL_XRAY_ALWAYS_INSTRUMENT, ABSL_XRAY_NEVER_INSTRUMENT, ABSL_XRAY_LOG_ARGS 479 // 480 // We define the ABSL_XRAY_ALWAYS_INSTRUMENT and ABSL_XRAY_NEVER_INSTRUMENT 481 // macro used as an attribute to mark functions that must always or never be 482 // instrumented by XRay. Currently, this is only supported in Clang/LLVM. 483 // 484 // For reference on the LLVM XRay instrumentation, see 485 // http://llvm.org/docs/XRay.html. 486 // 487 // A function with the XRAY_ALWAYS_INSTRUMENT macro attribute in its declaration 488 // will always get the XRay instrumentation sleds. These sleds may introduce 489 // some binary size and runtime overhead and must be used sparingly. 490 // 491 // These attributes only take effect when the following conditions are met: 492 // 493 // * The file/target is built in at least C++11 mode, with a Clang compiler 494 // that supports XRay attributes. 495 // * The file/target is built with the -fxray-instrument flag set for the 496 // Clang/LLVM compiler. 497 // * The function is defined in the translation unit (the compiler honors the 498 // attribute in either the definition or the declaration, and must match). 499 // 500 // There are cases when, even when building with XRay instrumentation, users 501 // might want to control specifically which functions are instrumented for a 502 // particular build using special-case lists provided to the compiler. These 503 // special case lists are provided to Clang via the 504 // -fxray-always-instrument=... and -fxray-never-instrument=... flags. The 505 // attributes in source take precedence over these special-case lists. 506 // 507 // To disable the XRay attributes at build-time, users may define 508 // ABSL_NO_XRAY_ATTRIBUTES. Do NOT define ABSL_NO_XRAY_ATTRIBUTES on specific 509 // packages/targets, as this may lead to conflicting definitions of functions at 510 // link-time. 511 // 512 // XRay isn't currently supported on Android: 513 // https://github.com/android/ndk/issues/368 514 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::xray_always_instrument) && \ 515 !defined(ABSL_NO_XRAY_ATTRIBUTES) && !defined(__ANDROID__) 516 #define ABSL_XRAY_ALWAYS_INSTRUMENT [[clang::xray_always_instrument]] 517 #define ABSL_XRAY_NEVER_INSTRUMENT [[clang::xray_never_instrument]] 518 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::xray_log_args) 519 #define ABSL_XRAY_LOG_ARGS(N) \ 520 [[clang::xray_always_instrument, clang::xray_log_args(N)]] 521 #else 522 #define ABSL_XRAY_LOG_ARGS(N) [[clang::xray_always_instrument]] 523 #endif 524 #else 525 #define ABSL_XRAY_ALWAYS_INSTRUMENT 526 #define ABSL_XRAY_NEVER_INSTRUMENT 527 #define ABSL_XRAY_LOG_ARGS(N) 528 #endif 529 530 // ABSL_ATTRIBUTE_REINITIALIZES 531 // 532 // Indicates that a member function reinitializes the entire object to a known 533 // state, independent of the previous state of the object. 534 // 535 // The clang-tidy check bugprone-use-after-move allows member functions marked 536 // with this attribute to be called on objects that have been moved from; 537 // without the attribute, this would result in a use-after-move warning. 538 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::reinitializes) 539 #define ABSL_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]] 540 #else 541 #define ABSL_ATTRIBUTE_REINITIALIZES 542 #endif 543 544 // ----------------------------------------------------------------------------- 545 // Variable Attributes 546 // ----------------------------------------------------------------------------- 547 548 // ABSL_ATTRIBUTE_UNUSED 549 // 550 // Prevents the compiler from complaining about variables that appear unused. 551 // 552 // For code or headers that are assured to only build with C++17 and up, prefer 553 // just using the standard '[[maybe_unused]]' directly over this macro. 554 // 555 // Due to differences in positioning requirements between the old, compiler 556 // specific __attribute__ syntax and the now standard [[maybe_unused]], this 557 // macro does not attempt to take advantage of '[[maybe_unused]]'. 558 #if ABSL_HAVE_ATTRIBUTE(unused) || (defined(__GNUC__) && !defined(__clang__)) 559 #undef ABSL_ATTRIBUTE_UNUSED 560 #define ABSL_ATTRIBUTE_UNUSED __attribute__((__unused__)) 561 #else 562 #define ABSL_ATTRIBUTE_UNUSED 563 #endif 564 565 // ABSL_ATTRIBUTE_INITIAL_EXEC 566 // 567 // Tells the compiler to use "initial-exec" mode for a thread-local variable. 568 // See http://people.redhat.com/drepper/tls.pdf for the gory details. 569 #if ABSL_HAVE_ATTRIBUTE(tls_model) || (defined(__GNUC__) && !defined(__clang__)) 570 #define ABSL_ATTRIBUTE_INITIAL_EXEC __attribute__((tls_model("initial-exec"))) 571 #else 572 #define ABSL_ATTRIBUTE_INITIAL_EXEC 573 #endif 574 575 // ABSL_ATTRIBUTE_PACKED 576 // 577 // Instructs the compiler not to use natural alignment for a tagged data 578 // structure, but instead to reduce its alignment to 1. 579 // 580 // Therefore, DO NOT APPLY THIS ATTRIBUTE TO STRUCTS CONTAINING ATOMICS. Doing 581 // so can cause atomic variables to be mis-aligned and silently violate 582 // atomicity on x86. 583 // 584 // This attribute can either be applied to members of a structure or to a 585 // structure in its entirety. Applying this attribute (judiciously) to a 586 // structure in its entirety to optimize the memory footprint of very 587 // commonly-used structs is fine. Do not apply this attribute to a structure in 588 // its entirety if the purpose is to control the offsets of the members in the 589 // structure. Instead, apply this attribute only to structure members that need 590 // it. 591 // 592 // When applying ABSL_ATTRIBUTE_PACKED only to specific structure members the 593 // natural alignment of structure members not annotated is preserved. Aligned 594 // member accesses are faster than non-aligned member accesses even if the 595 // targeted microprocessor supports non-aligned accesses. 596 #if ABSL_HAVE_ATTRIBUTE(packed) || (defined(__GNUC__) && !defined(__clang__)) 597 #define ABSL_ATTRIBUTE_PACKED __attribute__((__packed__)) 598 #else 599 #define ABSL_ATTRIBUTE_PACKED 600 #endif 601 602 // ABSL_ATTRIBUTE_FUNC_ALIGN 603 // 604 // Tells the compiler to align the function start at least to certain 605 // alignment boundary 606 #if ABSL_HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) 607 #define ABSL_ATTRIBUTE_FUNC_ALIGN(bytes) __attribute__((aligned(bytes))) 608 #else 609 #define ABSL_ATTRIBUTE_FUNC_ALIGN(bytes) 610 #endif 611 612 // ABSL_FALLTHROUGH_INTENDED 613 // 614 // Annotates implicit fall-through between switch labels, allowing a case to 615 // indicate intentional fallthrough and turn off warnings about any lack of a 616 // `break` statement. The ABSL_FALLTHROUGH_INTENDED macro should be followed by 617 // a semicolon and can be used in most places where `break` can, provided that 618 // no statements exist between it and the next switch label. 619 // 620 // Example: 621 // 622 // switch (x) { 623 // case 40: 624 // case 41: 625 // if (truth_is_out_there) { 626 // ++x; 627 // ABSL_FALLTHROUGH_INTENDED; // Use instead of/along with annotations 628 // // in comments 629 // } else { 630 // return x; 631 // } 632 // case 42: 633 // ... 634 // 635 // Notes: When supported, GCC and Clang can issue a warning on switch labels 636 // with unannotated fallthrough using the warning `-Wimplicit-fallthrough`. See 637 // clang documentation on language extensions for details: 638 // https://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough 639 // 640 // When used with unsupported compilers, the ABSL_FALLTHROUGH_INTENDED macro has 641 // no effect on diagnostics. In any case this macro has no effect on runtime 642 // behavior and performance of code. 643 644 #ifdef ABSL_FALLTHROUGH_INTENDED 645 #error "ABSL_FALLTHROUGH_INTENDED should not be defined." 646 #elif ABSL_HAVE_CPP_ATTRIBUTE(fallthrough) 647 #define ABSL_FALLTHROUGH_INTENDED [[fallthrough]] 648 #elif ABSL_HAVE_CPP_ATTRIBUTE(clang::fallthrough) 649 #define ABSL_FALLTHROUGH_INTENDED [[clang::fallthrough]] 650 #elif ABSL_HAVE_CPP_ATTRIBUTE(gnu::fallthrough) 651 #define ABSL_FALLTHROUGH_INTENDED [[gnu::fallthrough]] 652 #else 653 #define ABSL_FALLTHROUGH_INTENDED \ 654 do { \ 655 } while (0) 656 #endif 657 658 // ABSL_DEPRECATED() 659 // 660 // Marks a deprecated class, struct, enum, function, method and variable 661 // declarations. The macro argument is used as a custom diagnostic message (e.g. 662 // suggestion of a better alternative). 663 // 664 // For code or headers that are assured to only build with C++14 and up, prefer 665 // just using the standard `[[deprecated("message")]]` directly over this macro. 666 // 667 // Examples: 668 // 669 // class ABSL_DEPRECATED("Use Bar instead") Foo {...}; 670 // 671 // ABSL_DEPRECATED("Use Baz() instead") void Bar() {...} 672 // 673 // template <typename T> 674 // ABSL_DEPRECATED("Use DoThat() instead") 675 // void DoThis(); 676 // 677 // enum FooEnum { 678 // kBar ABSL_DEPRECATED("Use kBaz instead"), 679 // }; 680 // 681 // Every usage of a deprecated entity will trigger a warning when compiled with 682 // GCC/Clang's `-Wdeprecated-declarations` option. Google's production toolchain 683 // turns this warning off by default, instead relying on clang-tidy to report 684 // new uses of deprecated code. 685 #if ABSL_HAVE_ATTRIBUTE(deprecated) 686 #define ABSL_DEPRECATED(message) __attribute__((deprecated(message))) 687 #else 688 #define ABSL_DEPRECATED(message) 689 #endif 690 691 // When deprecating Abseil code, it is sometimes necessary to turn off the 692 // warning within Abseil, until the deprecated code is actually removed. The 693 // deprecated code can be surrounded with these directives to achieve that 694 // result. 695 // 696 // class ABSL_DEPRECATED("Use Bar instead") Foo; 697 // 698 // ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING 699 // Baz ComputeBazFromFoo(Foo f); 700 // ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING 701 #if defined(__GNUC__) || defined(__clang__) 702 // Clang also supports these GCC pragmas. 703 #define ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING \ 704 _Pragma("GCC diagnostic push") \ 705 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 706 #define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING \ 707 _Pragma("GCC diagnostic pop") 708 #elif defined(_MSC_VER) 709 #define ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING \ 710 _Pragma("warning(push)") _Pragma("warning(disable: 4996)") 711 #define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING \ 712 _Pragma("warning(pop)") 713 #else 714 #define ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING 715 #define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING 716 #endif // defined(__GNUC__) || defined(__clang__) 717 718 // ABSL_CONST_INIT 719 // 720 // A variable declaration annotated with the `ABSL_CONST_INIT` attribute will 721 // not compile (on supported platforms) unless the variable has a constant 722 // initializer. This is useful for variables with static and thread storage 723 // duration, because it guarantees that they will not suffer from the so-called 724 // "static init order fiasco". 725 // 726 // This attribute must be placed on the initializing declaration of the 727 // variable. Some compilers will give a -Wmissing-constinit warning when this 728 // attribute is placed on some other declaration but missing from the 729 // initializing declaration. 730 // 731 // In some cases (notably with thread_local variables), `ABSL_CONST_INIT` can 732 // also be used in a non-initializing declaration to tell the compiler that a 733 // variable is already initialized, reducing overhead that would otherwise be 734 // incurred by a hidden guard variable. Thus annotating all declarations with 735 // this attribute is recommended to potentially enhance optimization. 736 // 737 // Example: 738 // 739 // class MyClass { 740 // public: 741 // ABSL_CONST_INIT static MyType my_var; 742 // }; 743 // 744 // ABSL_CONST_INIT MyType MyClass::my_var = MakeMyType(...); 745 // 746 // For code or headers that are assured to only build with C++20 and up, prefer 747 // just using the standard `constinit` keyword directly over this macro. 748 // 749 // Note that this attribute is redundant if the variable is declared constexpr. 750 #if defined(__cpp_constinit) && __cpp_constinit >= 201907L 751 #define ABSL_CONST_INIT constinit 752 #elif ABSL_HAVE_CPP_ATTRIBUTE(clang::require_constant_initialization) 753 #define ABSL_CONST_INIT [[clang::require_constant_initialization]] 754 #else 755 #define ABSL_CONST_INIT 756 #endif 757 758 // ABSL_ATTRIBUTE_PURE_FUNCTION 759 // 760 // ABSL_ATTRIBUTE_PURE_FUNCTION is used to annotate declarations of "pure" 761 // functions. A function is pure if its return value is only a function of its 762 // arguments. The pure attribute prohibits a function from modifying the state 763 // of the program that is observable by means other than inspecting the 764 // function's return value. Declaring such functions with the pure attribute 765 // allows the compiler to avoid emitting some calls in repeated invocations of 766 // the function with the same argument values. 767 // 768 // Example: 769 // 770 // ABSL_ATTRIBUTE_PURE_FUNCTION std::string FormatTime(Time t); 771 #if ABSL_HAVE_CPP_ATTRIBUTE(gnu::pure) 772 #define ABSL_ATTRIBUTE_PURE_FUNCTION [[gnu::pure]] 773 #elif ABSL_HAVE_ATTRIBUTE(pure) 774 #define ABSL_ATTRIBUTE_PURE_FUNCTION __attribute__((pure)) 775 #else 776 // If the attribute isn't defined, we'll fallback to ABSL_MUST_USE_RESULT since 777 // pure functions are useless if its return is ignored. 778 #define ABSL_ATTRIBUTE_PURE_FUNCTION ABSL_MUST_USE_RESULT 779 #endif 780 781 // ABSL_ATTRIBUTE_CONST_FUNCTION 782 // 783 // ABSL_ATTRIBUTE_CONST_FUNCTION is used to annotate declarations of "const" 784 // functions. A const function is similar to a pure function, with one 785 // exception: Pure functions may return value that depend on a non-volatile 786 // object that isn't provided as a function argument, while the const function 787 // is guaranteed to return the same result given the same arguments. 788 // 789 // Example: 790 // 791 // ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Milliseconds(Duration d); 792 #if defined(_MSC_VER) && !defined(__clang__) 793 // Put the MSVC case first since MSVC seems to parse const as a C++ keyword. 794 #define ABSL_ATTRIBUTE_CONST_FUNCTION ABSL_ATTRIBUTE_PURE_FUNCTION 795 #elif ABSL_HAVE_CPP_ATTRIBUTE(gnu::const) 796 #define ABSL_ATTRIBUTE_CONST_FUNCTION [[gnu::const]] 797 #elif ABSL_HAVE_ATTRIBUTE(const) 798 #define ABSL_ATTRIBUTE_CONST_FUNCTION __attribute__((const)) 799 #else 800 // Since const functions are more restrictive pure function, we'll fallback to a 801 // pure function if the const attribute is not handled. 802 #define ABSL_ATTRIBUTE_CONST_FUNCTION ABSL_ATTRIBUTE_PURE_FUNCTION 803 #endif 804 805 // ABSL_ATTRIBUTE_LIFETIME_BOUND indicates that a resource owned by a function 806 // parameter or implicit object parameter is retained by the return value of the 807 // annotated function (or, for a parameter of a constructor, in the value of the 808 // constructed object). This attribute causes warnings to be produced if a 809 // temporary object does not live long enough. 810 // 811 // When applied to a reference parameter, the referenced object is assumed to be 812 // retained by the return value of the function. When applied to a non-reference 813 // parameter (for example, a pointer or a class type), all temporaries 814 // referenced by the parameter are assumed to be retained by the return value of 815 // the function. 816 // 817 // See also the upstream documentation: 818 // https://clang.llvm.org/docs/AttributeReference.html#lifetimebound 819 // https://learn.microsoft.com/en-us/cpp/code-quality/c26816?view=msvc-170 820 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::lifetimebound) 821 #define ABSL_ATTRIBUTE_LIFETIME_BOUND [[clang::lifetimebound]] 822 #elif ABSL_HAVE_CPP_ATTRIBUTE(msvc::lifetimebound) 823 #define ABSL_ATTRIBUTE_LIFETIME_BOUND [[msvc::lifetimebound]] 824 #elif ABSL_HAVE_ATTRIBUTE(lifetimebound) 825 #define ABSL_ATTRIBUTE_LIFETIME_BOUND __attribute__((lifetimebound)) 826 #else 827 #define ABSL_ATTRIBUTE_LIFETIME_BOUND 828 #endif 829 830 // ABSL_INTERNAL_ATTRIBUTE_VIEW indicates that a type acts like a view i.e. a 831 // raw (non-owning) pointer. This enables diagnoses similar to those enabled by 832 // ABSL_ATTRIBUTE_LIFETIME_BOUND. 833 // 834 // See the following links for details: 835 // https://reviews.llvm.org/D64448 836 // https://lists.llvm.org/pipermail/cfe-dev/2018-November/060355.html 837 #if ABSL_HAVE_CPP_ATTRIBUTE(gsl::Pointer) 838 #define ABSL_INTERNAL_ATTRIBUTE_VIEW [[gsl::Pointer]] 839 #else 840 #define ABSL_INTERNAL_ATTRIBUTE_VIEW 841 #endif 842 843 // ABSL_INTERNAL_ATTRIBUTE_OWNER indicates that a type acts like a smart 844 // (owning) pointer. This enables diagnoses similar to those enabled by 845 // ABSL_ATTRIBUTE_LIFETIME_BOUND. 846 // 847 // See the following links for details: 848 // https://reviews.llvm.org/D64448 849 // https://lists.llvm.org/pipermail/cfe-dev/2018-November/060355.html 850 #if ABSL_HAVE_CPP_ATTRIBUTE(gsl::Owner) 851 #define ABSL_INTERNAL_ATTRIBUTE_OWNER [[gsl::Owner]] 852 #else 853 #define ABSL_INTERNAL_ATTRIBUTE_OWNER 854 #endif 855 856 // ABSL_ATTRIBUTE_TRIVIAL_ABI 857 // Indicates that a type is "trivially relocatable" -- meaning it can be 858 // relocated without invoking the constructor/destructor, using a form of move 859 // elision. 860 // 861 // From a memory safety point of view, putting aside destructor ordering, it's 862 // safe to apply ABSL_ATTRIBUTE_TRIVIAL_ABI if an object's location 863 // can change over the course of its lifetime: if a constructor can be run one 864 // place, and then the object magically teleports to another place where some 865 // methods are run, and then the object teleports to yet another place where it 866 // is destroyed. This is notably not true for self-referential types, where the 867 // move-constructor must keep the self-reference up to date. If the type changed 868 // location without invoking the move constructor, it would have a dangling 869 // self-reference. 870 // 871 // The use of this teleporting machinery means that the number of paired 872 // move/destroy operations can change, and so it is a bad idea to apply this to 873 // a type meant to count the number of moves. 874 // 875 // Warning: applying this can, rarely, break callers. Objects passed by value 876 // will be destroyed at the end of the call, instead of the end of the 877 // full-expression containing the call. In addition, it changes the ABI 878 // of functions accepting this type by value (e.g. to pass in registers). 879 // 880 // See also the upstream documentation: 881 // https://clang.llvm.org/docs/AttributeReference.html#trivial-abi 882 // 883 // b/321691395 - This is currently disabled in open-source builds since 884 // compiler support differs. If system libraries compiled with GCC are mixed 885 // with libraries compiled with Clang, types will have different ideas about 886 // their ABI, leading to hard to debug crashes. 887 #define ABSL_ATTRIBUTE_TRIVIAL_ABI 888 889 // ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS 890 // 891 // Indicates a data member can be optimized to occupy no space (if it is empty) 892 // and/or its tail padding can be used for other members. 893 // 894 // For code that is assured to only build with C++20 or later, prefer using 895 // the standard attribute `[[no_unique_address]]` directly instead of this 896 // macro. 897 // 898 // https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/#c20-no_unique_address 899 // Current versions of MSVC have disabled `[[no_unique_address]]` since it 900 // breaks ABI compatibility, but offers `[[msvc::no_unique_address]]` for 901 // situations when it can be assured that it is desired. Since Abseil does not 902 // claim ABI compatibility in mixed builds, we can offer it unconditionally. 903 #if defined(_MSC_VER) && _MSC_VER >= 1929 904 #define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] 905 #elif ABSL_HAVE_CPP_ATTRIBUTE(no_unique_address) 906 #define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS [[no_unique_address]] 907 #else 908 #define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS 909 #endif 910 911 // ABSL_ATTRIBUTE_UNINITIALIZED 912 // 913 // GCC and Clang support a flag `-ftrivial-auto-var-init=<option>` (<option> 914 // can be "zero" or "pattern") that can be used to initialize automatic stack 915 // variables. Variables with this attribute will be left uninitialized, 916 // overriding the compiler flag. 917 // 918 // See https://clang.llvm.org/docs/AttributeReference.html#uninitialized 919 // and https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-uninitialized-variable-attribute 920 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::uninitialized) 921 #define ABSL_ATTRIBUTE_UNINITIALIZED [[clang::uninitialized]] 922 #elif ABSL_HAVE_CPP_ATTRIBUTE(gnu::uninitialized) 923 #define ABSL_ATTRIBUTE_UNINITIALIZED [[gnu::uninitialized]] 924 #elif ABSL_HAVE_ATTRIBUTE(uninitialized) 925 #define ABSL_ATTRIBUTE_UNINITIALIZED __attribute__((uninitialized)) 926 #else 927 #define ABSL_ATTRIBUTE_UNINITIALIZED 928 #endif 929 930 // ABSL_ATTRIBUTE_WARN_UNUSED 931 // 932 // Compilers routinely warn about trivial variables that are unused. For 933 // non-trivial types, this warning is suppressed since the 934 // constructor/destructor may be intentional and load-bearing, for example, with 935 // a RAII scoped lock. 936 // 937 // For example: 938 // 939 // class ABSL_ATTRIBUTE_WARN_UNUSED MyType { 940 // public: 941 // MyType(); 942 // ~MyType(); 943 // }; 944 // 945 // void foo() { 946 // // Warns with ABSL_ATTRIBUTE_WARN_UNUSED attribute present. 947 // MyType unused; 948 // } 949 // 950 // See https://clang.llvm.org/docs/AttributeReference.html#warn-unused and 951 // https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html#index-warn_005funused-type-attribute 952 #if ABSL_HAVE_CPP_ATTRIBUTE(gnu::warn_unused) 953 #define ABSL_ATTRIBUTE_WARN_UNUSED [[gnu::warn_unused]] 954 #else 955 #define ABSL_ATTRIBUTE_WARN_UNUSED 956 #endif 957 958 #endif // ABSL_BASE_ATTRIBUTES_H_ 959