Commit ec583f2d by Mike Kruskal Committed by Copybara-Service

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
parent c353e259
...@@ -37,8 +37,8 @@ ...@@ -37,8 +37,8 @@
#include "absl/log/internal/check_impl.h" #include "absl/log/internal/check_impl.h"
#define ABSL_CHECK(condition) ABSL_CHECK_IMPL(condition) #define ABSL_CHECK(condition) ABSL_CHECK_IMPL(condition, #condition)
#define ABSL_QCHECK(condition) ABSL_QCHECK_IMPL(condition) #define ABSL_QCHECK(condition) ABSL_QCHECK_IMPL(condition, #condition)
#define ABSL_PCHECK(condition) ABSL_PCHECK_IMPL(condition) #define ABSL_PCHECK(condition) ABSL_PCHECK_IMPL(condition)
#define ABSL_DCHECK(condition) ABSL_DCHECK_IMPL(condition) #define ABSL_DCHECK(condition) ABSL_DCHECK_IMPL(condition)
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
// Might produce a message like: // Might produce a message like:
// //
// Check failed: !cheese.empty() Out of Cheese // Check failed: !cheese.empty() Out of Cheese
#define CHECK(condition) ABSL_CHECK_IMPL(condition) #define CHECK(condition) ABSL_CHECK_IMPL(condition, #condition)
// QCHECK() // QCHECK()
// //
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
// not run registered error handlers (as `QFATAL`). It is useful when the // not run registered error handlers (as `QFATAL`). It is useful when the
// problem is definitely unrelated to program flow, e.g. when validating user // problem is definitely unrelated to program flow, e.g. when validating user
// input. // input.
#define QCHECK(condition) ABSL_QCHECK_IMPL(condition) #define QCHECK(condition) ABSL_QCHECK_IMPL(condition, #condition)
// PCHECK() // PCHECK()
// //
......
...@@ -120,6 +120,19 @@ TEST(CHECKDeathTest, TestChecksWithSideEffects) { ...@@ -120,6 +120,19 @@ TEST(CHECKDeathTest, TestChecksWithSideEffects) {
#if GTEST_HAS_DEATH_TEST #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) { TEST(CHECKDeachTest, TestOrderOfInvocationsBetweenCheckAndMessage) {
int counter = 0; int counter = 0;
......
...@@ -22,22 +22,23 @@ ...@@ -22,22 +22,23 @@
#include "absl/log/internal/strip.h" #include "absl/log/internal/strip.h"
// CHECK // CHECK
#define ABSL_CHECK_IMPL(condition) \ #define ABSL_CHECK_IMPL(condition, condition_str) \
ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, \ ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, \
ABSL_PREDICT_FALSE(!(condition))) \ 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_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, \
ABSL_PREDICT_FALSE(!(condition))) \ 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 #ifndef NDEBUG
#define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(condition) #define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(condition, #condition)
#else #else
#define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(true || (condition)) #define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(true || (condition), "true")
#endif #endif
// CHECK_EQ // CHECK_EQ
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment