From cffdb8d341d5012a3bd7315e954265abcc9884bb Mon Sep 17 00:00:00 2001 From: Jason Lokerson Date: Sat, 23 Apr 2016 21:33:30 -0700 Subject: [PATCH] Add explicit operator bool overload This is intended to silence performance warnings in VS2015. Also make a change to the `ASSERT_TRUE` and `ASSERT_FALSE` macros in order to eliminate the performance warning. --- contrib/gtest-1.7.0/fused-src/gtest/gtest.h | 4 ++-- src/autowiring/Autowired.h | 4 ++++ src/autowiring/test/AutoFilterTest.cpp | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/contrib/gtest-1.7.0/fused-src/gtest/gtest.h b/contrib/gtest-1.7.0/fused-src/gtest/gtest.h index 4f3804f70..2edf8a54f 100644 --- a/contrib/gtest-1.7.0/fused-src/gtest/gtest.h +++ b/contrib/gtest-1.7.0/fused-src/gtest/gtest.h @@ -19325,13 +19325,13 @@ class TestWithParam : public Test, public WithParamInterface { // AssertionResult. For more information on how to use AssertionResult with // these macros see comments on that class. #define EXPECT_TRUE(condition) \ - GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ + GTEST_TEST_BOOLEAN_((bool)(condition), #condition, false, true, \ GTEST_NONFATAL_FAILURE_) #define EXPECT_FALSE(condition) \ GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ GTEST_NONFATAL_FAILURE_) #define ASSERT_TRUE(condition) \ - GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ + GTEST_TEST_BOOLEAN_(((bool)(condition)), #condition, false, true, \ GTEST_FATAL_FAILURE_) #define ASSERT_FALSE(condition) \ GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ diff --git a/src/autowiring/Autowired.h b/src/autowiring/Autowired.h index 63bb9493b..fa577ee48 100644 --- a/src/autowiring/Autowired.h +++ b/src/autowiring/Autowired.h @@ -130,6 +130,10 @@ class Autowired: template bool operator!=(const std::shared_ptr& rhs) const { return this->m_ptr != rhs; } + explicit operator bool(void) const { + return this->operator const std::shared_ptr&().get() != nullptr; + } + operator T*(void) const { return this->operator const std::shared_ptr&().get(); } diff --git a/src/autowiring/test/AutoFilterTest.cpp b/src/autowiring/test/AutoFilterTest.cpp index b7b198f4d..79be10050 100644 --- a/src/autowiring/test/AutoFilterTest.cpp +++ b/src/autowiring/test/AutoFilterTest.cpp @@ -396,8 +396,8 @@ TEST_F(AutoFilterTest, SingleImmediate) { Decoration dec; packet->DecorateImmediate(dec); - ASSERT_TRUE(fgp->m_called == 1) << "Filter should called " << fgp->m_called << " times, expected 1"; - ASSERT_TRUE(autowiring::get<0>(fgp->m_args).i == pattern) << "Filter argument yielded " << autowiring::get<0>(fgp->m_args).i << "expected " << pattern; + ASSERT_EQ(1, fgp->m_called) << "Filter should called " << fgp->m_called << " times, expected 1"; + ASSERT_EQ(pattern, autowiring::get<0>(fgp->m_args).i) << "Filter argument yielded " << autowiring::get<0>(fgp->m_args).i << "expected " << pattern; } ASSERT_EQ(0, factory->GetOutstandingPacketCount()) << "Destroyed packet remains outstanding";