diff --git a/include/internal/catch_tostring.hpp b/include/internal/catch_tostring.hpp index ae78e1f9..b463e4ff 100644 --- a/include/internal/catch_tostring.hpp +++ b/include/internal/catch_tostring.hpp @@ -79,6 +79,25 @@ namespace Detail { } }; + // For display purposes only. + // Does not consider endian-ness + template + std::string rawMemoryToString( T value ) { + union + { + T value; + unsigned char bytes[sizeof(T)]; + } valueAsBuffer; + + valueAsBuffer.value = value; + + std::ostringstream oss; + oss << "0x"; + for( unsigned char* cp = valueAsBuffer.bytes; cp < valueAsBuffer.bytes+sizeof(T); ++cp ) + oss << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)*cp; + return oss.str(); + } + } // end namespace Detail template @@ -94,9 +113,18 @@ struct StringMaker { static std::string convert( U* p ) { if( !p ) return INTERNAL_CATCH_STRINGIFY( NULL ); - std::ostringstream oss; - oss << "0x" << std::hex << reinterpret_cast( p ); - return oss.str(); + else + return Detail::rawMemoryToString( p ); + } +}; + +template +struct StringMaker { + static std::string convert( R C::* p ) { + if( !p ) + return INTERNAL_CATCH_STRINGIFY( NULL ); + else + return Detail::rawMemoryToString( p ); } }; diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 52b4db55..3bf4d6c2 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -750,5 +750,5 @@ with expansion: "first" == "second" =============================================================================== -122 test cases - 36 failed (675 assertions - 91 failed) +123 test cases - 36 failed (676 assertions - 91 failed) diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 81ee03db..64ed0577 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -6366,7 +6366,21 @@ TrickyTests.cpp:: PASSED: REQUIRE( a == &foo ) with expansion: - 1 == 1 + 0x == 0x + +------------------------------------------------------------------------------- +Comparing member function pointers +------------------------------------------------------------------------------- +TrickyTests.cpp: +............................................................................... + +TrickyTests.cpp:: +PASSED: + CHECK( m == &S::f ) +with expansion: + 0x + == + 0x ------------------------------------------------------------------------------- pointer to class @@ -7144,5 +7158,5 @@ with expansion: true =============================================================================== -122 test cases - 51 failed (694 assertions - 110 failed) +123 test cases - 51 failed (695 assertions - 110 failed) diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index e28449ca..58a1d151 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,5 +1,5 @@ - + @@ -514,6 +514,7 @@ TrickyTests.cpp: + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 9bebc628..efbb16d3 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -6637,7 +6637,20 @@ there" a == &foo - 1 == 1 + 0x == 0x + + + + + + + + m == &S::f + + + 0x +== +0x @@ -7405,7 +7418,7 @@ there" - + - + diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp index 624ba264..f8af61c2 100644 --- a/projects/SelfTest/TrickyTests.cpp +++ b/projects/SelfTest/TrickyTests.cpp @@ -356,6 +356,20 @@ TEST_CASE( "Comparing function pointers", "[Tricky][function pointer]" ) REQUIRE( a == &foo ); } +struct S +{ + void f() {} +}; + + +TEST_CASE( "Comparing member function pointers", "[Tricky][member function pointer]" ) +{ + typedef void (S::*MF)(); + MF m = &S::f; + + CHECK( m == &S::f ); +} + class ClassName {}; TEST_CASE( "pointer to class", "[Tricky]" ) diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj index e8848237..e61b82de 100644 --- a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj +++ b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj @@ -581,7 +581,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = ""; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; USER_HEADER_SEARCH_PATHS = "\"$(PROJECT_DIR)/../../../include\""; @@ -624,7 +624,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = ""; SDKROOT = macosx; USER_HEADER_SEARCH_PATHS = "\"$(PROJECT_DIR)/../../../include\""; };