summaryrefslogtreecommitdiff
path: root/absl/log
diff options
context:
space:
mode:
authorGravatar Mike Kruskal <mkruskal@google.com>2022-12-08 13:44:17 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2022-12-08 13:45:07 -0800
commitec583f2df279c86a8e8ba123b8929e92d2ee00f2 (patch)
tree645486dfd5bc61d94eaaf938f33e8b6314b2b1a3 /absl/log
parentc353e2597f7f24afbcd3bb34753d3e580bcee8ad (diff)
Fixing macro expansion changes in new logging macros.
This was an unintentional behavior change when we added a new layer of macros. Not using function-like macro aliases would get around this, but unfortunately that would flood the macro namespace downstream with CHECK and LOG (and break existing code). Note, the old behavior only applied to CHECK and QCHECK. Other CHECK macros already had multiple layers of function-like macros and were unaffected. PiperOrigin-RevId: 493984662 Change-Id: I9a050dcaf01f2b6935f02cd42e23bc3a4d5fc62a
Diffstat (limited to 'absl/log')
-rw-r--r--absl/log/absl_check.h4
-rw-r--r--absl/log/check.h4
-rw-r--r--absl/log/check_test_impl.h13
-rw-r--r--absl/log/internal/check_impl.h15
4 files changed, 25 insertions, 11 deletions
diff --git a/absl/log/absl_check.h b/absl/log/absl_check.h
index b8428bf7..2775adbe 100644
--- a/absl/log/absl_check.h
+++ b/absl/log/absl_check.h
@@ -37,8 +37,8 @@
#include "absl/log/internal/check_impl.h"
-#define ABSL_CHECK(condition) ABSL_CHECK_IMPL(condition)
-#define ABSL_QCHECK(condition) ABSL_QCHECK_IMPL(condition)
+#define ABSL_CHECK(condition) ABSL_CHECK_IMPL(condition, #condition)
+#define ABSL_QCHECK(condition) ABSL_QCHECK_IMPL(condition, #condition)
#define ABSL_PCHECK(condition) ABSL_PCHECK_IMPL(condition)
#define ABSL_DCHECK(condition) ABSL_DCHECK_IMPL(condition)
diff --git a/absl/log/check.h b/absl/log/check.h
index 172436a6..ef1bd531 100644
--- a/absl/log/check.h
+++ b/absl/log/check.h
@@ -54,7 +54,7 @@
// Might produce a message like:
//
// Check failed: !cheese.empty() Out of Cheese
-#define CHECK(condition) ABSL_CHECK_IMPL(condition)
+#define CHECK(condition) ABSL_CHECK_IMPL(condition, #condition)
// QCHECK()
//
@@ -62,7 +62,7 @@
// not run registered error handlers (as `QFATAL`). It is useful when the
// problem is definitely unrelated to program flow, e.g. when validating user
// input.
-#define QCHECK(condition) ABSL_QCHECK_IMPL(condition)
+#define QCHECK(condition) ABSL_QCHECK_IMPL(condition, #condition)
// PCHECK()
//
diff --git a/absl/log/check_test_impl.h b/absl/log/check_test_impl.h
index bcf5711f..2c09a60c 100644
--- a/absl/log/check_test_impl.h
+++ b/absl/log/check_test_impl.h
@@ -120,6 +120,19 @@ TEST(CHECKDeathTest, TestChecksWithSideEffects) {
#if GTEST_HAS_DEATH_TEST
+TEST(CHECKTest, TestMacroExpansionInMessage) {
+#define MACRO(x) x
+ auto MessageGen = []() { ABSL_TEST_CHECK(MACRO(false)); };
+ EXPECT_DEATH(MessageGen(), HasSubstr("MACRO(false)"));
+#undef MACRO
+}
+
+TEST(CHECKTest, TestNestedMacroExpansionInMessage) {
+#define MACRO(x) x
+ EXPECT_DEATH(ABSL_TEST_CHECK(MACRO(false)), HasSubstr("MACRO(false)"));
+#undef MACRO
+}
+
TEST(CHECKDeachTest, TestOrderOfInvocationsBetweenCheckAndMessage) {
int counter = 0;
diff --git a/absl/log/internal/check_impl.h b/absl/log/internal/check_impl.h
index 301b2915..d3238861 100644
--- a/absl/log/internal/check_impl.h
+++ b/absl/log/internal/check_impl.h
@@ -22,22 +22,23 @@
#include "absl/log/internal/strip.h"
// CHECK
-#define ABSL_CHECK_IMPL(condition) \
+#define ABSL_CHECK_IMPL(condition, condition_str) \
ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, \
ABSL_PREDICT_FALSE(!(condition))) \
- ABSL_LOG_INTERNAL_CHECK(#condition).InternalStream()
+ ABSL_LOG_INTERNAL_CHECK(condition_str).InternalStream()
-#define ABSL_QCHECK_IMPL(condition) \
+#define ABSL_QCHECK_IMPL(condition, condition_str) \
ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, \
ABSL_PREDICT_FALSE(!(condition))) \
- ABSL_LOG_INTERNAL_QCHECK(#condition).InternalStream()
+ ABSL_LOG_INTERNAL_QCHECK(condition_str).InternalStream()
-#define ABSL_PCHECK_IMPL(condition) ABSL_CHECK_IMPL(condition).WithPerror()
+#define ABSL_PCHECK_IMPL(condition) \
+ ABSL_CHECK_IMPL(condition, #condition).WithPerror()
#ifndef NDEBUG
-#define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(condition)
+#define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(condition, #condition)
#else
-#define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(true || (condition))
+#define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(true || (condition), "true")
#endif
// CHECK_EQ