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 |
|---|---|---|
| .. | ||
| internal | Loading commit data... | |
| BUILD.bazel | Loading commit data... | |
| CMakeLists.txt | Loading commit data... | |
| attributes.h | Loading commit data... | |
| bit_cast_test.cc | Loading commit data... | |
| c_header_test.c | Loading commit data... | |
| call_once.h | Loading commit data... | |
| call_once_test.cc | Loading commit data... | |
| casts.h | Loading commit data... | |
| config.h | Loading commit data... | |
| config_test.cc | Loading commit data... | |
| const_init.h | Loading commit data... | |
| dynamic_annotations.h | Loading commit data... | |
| exception_safety_testing_test.cc | Loading commit data... | |
| inline_variable_test.cc | Loading commit data... | |
| inline_variable_test_a.cc | Loading commit data... | |
| inline_variable_test_b.cc | Loading commit data... | |
| invoke_test.cc | Loading commit data... | |
| log_severity.cc | Loading commit data... | |
| log_severity.h | Loading commit data... | |
| log_severity_test.cc | Loading commit data... | |
| macros.h | Loading commit data... | |
| no_destructor.h | Loading commit data... | |
| no_destructor_benchmark.cc | Loading commit data... | |
| no_destructor_test.cc | Loading commit data... | |
| nullability.h | Loading commit data... | |
| nullability_default_nonnull_test.cc | Loading commit data... | |
| nullability_test.cc | Loading commit data... | |
| optimization.h | Loading commit data... | |
| optimization_test.cc | Loading commit data... | |
| options.h | Loading commit data... | |
| policy_checks.h | Loading commit data... | |
| port.h | Loading commit data... | |
| prefetch.h | Loading commit data... | |
| prefetch_test.cc | Loading commit data... | |
| raw_logging_test.cc | Loading commit data... | |
| spinlock_test_common.cc | Loading commit data... | |
| thread_annotations.h | Loading commit data... | |
| throw_delegate_test.cc | Loading commit data... |