Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Unified Diff: base/logging_unittest.cc

Issue 2515283002: logging: Provide a specific MakeCheckOpValueString overload for functions (Closed)
Patch Set: Prevent the empty functions from being optimized Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« base/logging.h ('K') | « base/logging.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/logging_unittest.cc
diff --git a/base/logging_unittest.cc b/base/logging_unittest.cc
index 8a20c54fb4c605734bf45c4b8bb582a76276e104..87a357ab781e4bacfe52f27285ea37516b0cc2ef 100644
--- a/base/logging_unittest.cc
+++ b/base/logging_unittest.cc
@@ -217,6 +217,13 @@ 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() {}
Nico 2016/11/23 18:09:26 nit: newline after this
TEST_F(LoggingTest, Dcheck) {
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
// Release build.
@@ -258,6 +265,26 @@ 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.
+ void (*fp1)() = DcheckEmptyFunction1;
+ void (*fp2)() = DcheckEmptyFunction2;
+ void (*fp3)() = DcheckEmptyFunction1;
+ DCHECK_EQ(fp1, fp3);
+ EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count);
Nico 2016/11/23 18:09:26 This is super confusing – it looks like fp1 and fp
+ DCHECK_EQ(fp1, fp2);
+ EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count);
+ struct MemberFunctions {
+ static void MemberFunction1(){};
+ static void TestDCHECK() {
+ void (*fp)() = MemberFunction1;
+ DCHECK_EQ(fp, MemberFunction1);
+ EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count);
+ DCHECK_EQ(fp, TestDCHECK);
+ EXPECT_EQ(DCHECK_IS_ON() ? 3 : 0, log_sink_call_count);
+ }
+ };
+ MemberFunctions::TestDCHECK();
}
TEST_F(LoggingTest, DcheckReleaseBehavior) {
« base/logging.h ('K') | « base/logging.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698