diff options
-rw-r--r-- | absl/log/internal/conditions.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/absl/log/internal/conditions.h b/absl/log/internal/conditions.h index b89f1dfd..b3ce2574 100644 --- a/absl/log/internal/conditions.h +++ b/absl/log/internal/conditions.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 |