diff options
Diffstat (limited to 'absl/log/internal/conditions.h')
-rw-r--r-- | absl/log/internal/conditions.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/absl/log/internal/conditions.h b/absl/log/internal/conditions.h index b89f1dfd..f576d650 100644 --- a/absl/log/internal/conditions.h +++ b/absl/log/internal/conditions.h @@ -23,7 +23,7 @@ #ifndef ABSL_LOG_INTERNAL_CONDITIONS_H_ #define ABSL_LOG_INTERNAL_CONDITIONS_H_ -#ifdef _WIN32 +#if defined(_WIN32) || defined(__hexagon__) #include <cstdlib> #else #include <unistd.h> @@ -56,9 +56,15 @@ // the ternary expression does a better job avoiding spurious diagnostics // (dangling else, missing switch case) and preserving noreturn semantics (e.g. // on `LOG(FATAL)`) without requiring braces. +// +// The `switch` ensures that this expansion is the begnning of a statement (as +// opposed to an expression) and prevents shenanigans like +// `AFunction(LOG(INFO))` and `decltype(LOG(INFO))`. The apparently-redundant +// `default` case makes the condition more amenable to Clang dataflow analysis. #define ABSL_LOG_INTERNAL_STATELESS_CONDITION(condition) \ switch (0) \ case 0: \ + default: \ !(condition) ? (void)0 : ::absl::log_internal::Voidify()&& // `ABSL_LOG_INTERNAL_STATEFUL_CONDITION` applies a condition like |