Also fix the old definition by verifying that the condition is contextually convertible to bool. The new C++20 definition reduces codegen bloat and guarantees fast performance while still retaining the expression (so that unused-variable warnings don't trigger). As an example where this makes a difference, compare the following snippet under `-DABSL_INTERNAL_CPLUSPLUS_LANG=202002`: https://godbolt.org/z/hjf59n84v ``` #include <stdlib.h> template<class T> struct S { S() { abort(); } static S const s; }; template<class T> S<T> const S<T>::s = {}; #if ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L #define ABSL_ASSERT(expr) (decltype((expr) ? void() : void())()) #else #define ABSL_ASSERT(expr) (false ? ((expr) ? void() : void()) : void()) #endif void foo() { ABSL_ASSERT(((void)&S<int>::s, true)); } ``` We see that, in unoptimized builds, code is still generated with the old definition of `ABSL_ASSERT`. Moreover, even under optimizations (with `-O2`), the call to abort() still lingers with the old definition of `ABSL_ASSERT`. Therefore the extra generated code can affect both compile- and run-time performance. PiperOrigin-RevId: 681563573 Change-Id: I7fbfadcc7fd198e8e1daf14615c33687f6b23af7
| Name |
Last commit
|
Last Update |
|---|---|---|
| .github | Loading commit data... | |
| CMake | Loading commit data... | |
| absl | Loading commit data... | |
| ci | Loading commit data... | |
| .clang-format | Loading commit data... | |
| .gitignore | Loading commit data... | |
| ABSEIL_ISSUE_TEMPLATE.md | Loading commit data... | |
| AUTHORS | Loading commit data... | |
| BUILD.bazel | Loading commit data... | |
| CMakeLists.txt | Loading commit data... | |
| CONTRIBUTING.md | Loading commit data... | |
| FAQ.md | Loading commit data... | |
| LICENSE | Loading commit data... | |
| MODULE.bazel | Loading commit data... | |
| PrivacyInfo.xcprivacy | Loading commit data... | |
| README.md | Loading commit data... | |
| UPGRADES.md | Loading commit data... | |
| WORKSPACE | Loading commit data... | |
| WORKSPACE.bzlmod | Loading commit data... | |
| conanfile.py | Loading commit data... | |
| create_lts.py | Loading commit data... |