From 78eb6b1c8c2492fea1783c09e946d094a8a5e905 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 3 Feb 2014 11:46:05 -0800 Subject: [PATCH] Fixed two tests to work with C++11/libc++. The tests attempted to compare two ostream&, but didn't really. In c++03, both decayed to void *, which wre then compared. In c++11, the ostreams are comvertible to bool, but only explicitly, and this failed to compile. Use a custom struct with operator== instead of ostream in these tests instead. --- test/mem_fun_cxx98.cpp | 18 +++++++++++++----- test/mem_fun_portable.cpp | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/test/mem_fun_cxx98.cpp b/test/mem_fun_cxx98.cpp index fba21dd..c289791 100644 --- a/test/mem_fun_cxx98.cpp +++ b/test/mem_fun_cxx98.cpp @@ -14,24 +14,32 @@ #include #include +struct Y { + Y(int y = 0) : y_(y) {} + bool operator==(const Y& rhs) { return y_ == rhs.y_; } +private: + int y_; + }; + struct X { int foo(int); - std::ostream& foo2(std::ostream&) const; + Y& foo2(Y&) const; }; int X::foo(int x) { return -x; } -std::ostream& X::foo2(std::ostream& x) const { return x; } +Y& X::foo2(Y& x) const { return x; } int main() { boost::function f; - boost::function f2; - + boost::function f2; + Y y1; + f = &X::foo; f2 = &X::foo2; X x; BOOST_TEST(f(&x, 5) == -5); - BOOST_TEST(f2(&x, boost::ref(std::cout)) == std::cout); + BOOST_TEST(f2(&x, boost::ref(y1)) == y1); return ::boost::report_errors(); } diff --git a/test/mem_fun_portable.cpp b/test/mem_fun_portable.cpp index b0dcd14..0251339 100644 --- a/test/mem_fun_portable.cpp +++ b/test/mem_fun_portable.cpp @@ -14,24 +14,32 @@ #include #include +struct Y { + Y(int y = 0) : y_(y) {} + bool operator==(const Y& rhs) { return y_ == rhs.y_; } +private: + int y_; + }; + struct X { int foo(int); - std::ostream& foo2(std::ostream&) const; + Y& foo2(Y&) const; }; int X::foo(int x) { return -x; } -std::ostream& X::foo2(std::ostream& x) const { return x; } +Y& X::foo2(Y& x) const { return x; } int main() { boost::function2 f; - boost::function2 f2; - + boost::function2 f2; + Y y1; + f = &X::foo; f2 = &X::foo2; X x; BOOST_TEST(f(&x, 5) == -5); - BOOST_TEST(f2(&x, boost::ref(std::cout)) == std::cout); + BOOST_TEST(f2(&x, boost::ref(y1)) == y1); return ::boost::report_errors(); }