| Index: base/logging_unittest.cc
|
| diff --git a/base/logging_unittest.cc b/base/logging_unittest.cc
|
| index 8a20c54fb4c605734bf45c4b8bb582a76276e104..f41cce2f43b390fa9603a14f3f689fe87d0dcb33 100644
|
| --- a/base/logging_unittest.cc
|
| +++ b/base/logging_unittest.cc
|
| @@ -217,6 +217,14 @@ TEST_F(LoggingTest, DcheckStreamsAreLazy) {
|
| #endif
|
| }
|
|
|
| +void DcheckEmptyFunction1() {
|
| + // Provide a body so that Release builds do not cause the compiler to
|
| + // optimize DcheckEmptyFunction1 and DcheckEmptyFunction2 as a single
|
| + // function, which breaks the Dcheck tests below.
|
| + LOG(INFO) << "DcheckEmptyFunction1";
|
| +}
|
| +void DcheckEmptyFunction2() {}
|
| +
|
| TEST_F(LoggingTest, Dcheck) {
|
| #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
|
| // Release build.
|
| @@ -258,6 +266,31 @@ TEST_F(LoggingTest, Dcheck) {
|
| EXPECT_EQ(0, log_sink_call_count);
|
| DCHECK_EQ(Animal::DOG, Animal::CAT);
|
| EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count);
|
| +
|
| + // Test DCHECK on functions and function pointers.
|
| + log_sink_call_count = 0;
|
| + struct MemberFunctions {
|
| + void MemberFunction1() {
|
| + // See the comment in DcheckEmptyFunction1().
|
| + LOG(INFO) << "Do not merge with MemberFunction2.";
|
| + }
|
| + void MemberFunction2() {}
|
| + };
|
| + void (MemberFunctions::*mp1)() = &MemberFunctions::MemberFunction1;
|
| + void (MemberFunctions::*mp2)() = &MemberFunctions::MemberFunction2;
|
| + void (*fp1)() = DcheckEmptyFunction1;
|
| + void (*fp2)() = DcheckEmptyFunction2;
|
| + void (*fp3)() = DcheckEmptyFunction1;
|
| + DCHECK_EQ(fp1, fp3);
|
| + EXPECT_EQ(0, log_sink_call_count);
|
| + DCHECK_EQ(mp1, &MemberFunctions::MemberFunction1);
|
| + EXPECT_EQ(0, log_sink_call_count);
|
| + DCHECK_EQ(mp2, &MemberFunctions::MemberFunction2);
|
| + EXPECT_EQ(0, log_sink_call_count);
|
| + DCHECK_EQ(fp1, fp2);
|
| + EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count);
|
| + DCHECK_EQ(mp2, &MemberFunctions::MemberFunction1);
|
| + EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count);
|
| }
|
|
|
| TEST_F(LoggingTest, DcheckReleaseBehavior) {
|
|
|