Open macong-earth opened 10 years ago
MSVC can't figure out how to print the argument. The intent of NotPrintable was to catch these cases (and it looks like GCC is letting it do that just fine) but it also looks like MSVC ships with a default print function for booleans that can also be used. I'm not entirely sure what the best fix would be... let me check what the language standard says about this case. The NotPrintable conversion should not be rated as high as the boolean one, since it was constructed specifically to be selected least likely.
You know what? We are seeing the same error with g++-4.8. We are using boost and -std=c++03 and the following version of hippomocks from the old git repo:
2010-12-14 [dascandy] Added no-exceptions support, added LGPLv2 header to make it clear once & for all. Fixed up some ifdef checks to check for the right thing. Made auto-expect changeable for the entire use of hippomocks instead of per-test. 37c825483c
#include <cstdio> // hippomocks needs printf defined
#include <boost/function.hpp>
#include "hippomocks.h"
using namespace HippoMocks;
struct A
{
virtual void f(boost::function<void (int)> arg);
};
int main(void)
{
MockRepository mock;
A* aptr = mock.Mock<A>();
mock.ExpectCall(aptr, A::f);
return 0;
}
It's generating the following output:
g++ boost_function.cpp
In file included from boost_function.cpp:3:0:
hippomocks.h: In instantiation of ‘static void HippoMocks::printArg<T>::print(std::ostream&, T, bool) [with T = boost::function<void(int)>; std::ostream = std::basic_ostream<char>]’:
hippomocks.h:492:35: required from ‘void HippoMocks::ref_tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>::printTo(std::ostream&) const [with A = boost::function<void(int)>; B = HippoMocks::NullType; C = HippoMocks::NullType; D = HippoMocks::NullType; E = HippoMocks::NullType; F = HippoMocks::NullType; G = HippoMocks::NullType; H = HippoMocks::NullType; I = HippoMocks::NullType; J = HippoMocks::NullType; K = HippoMocks::NullType; L = HippoMocks::NullType; M = HippoMocks::NullType; N = HippoMocks::NullType; O = HippoMocks::NullType; P = HippoMocks::NullType; std::ostream = std::basic_ostream<char>]’
boost_function.cpp:20:1: required from here
hippomocks.h:349:6: error: ambiguous overload for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘boost::function<void(int)>’)
os << arg;
^
hippomocks.h:349:6: note: candidates are:
In file included from /usr/include/c++/4.8/iostream:39:0,
from /usr/local/include/boost/assert.hpp:84,
from /usr/local/include/boost/function/function_base.hpp:20,
from /usr/local/include/boost/function/detail/prologue.hpp:17,
from /usr/local/include/boost/function.hpp:24,
from boost_function.cpp:2:
/usr/include/c++/4.8/ostream:174:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(bool __n)
^
In file included from boost_function.cpp:3:0:
hippomocks.h:330:22: note: std::ostream& HippoMocks::operator<<(std::ostream&, const HippoMocks::NotPrintable&)
inline std::ostream &operator<<(std::ostream &os, NotPrintable const&)
^
make: *** [default] Error 1
Glad to see some hippomock activity, I'm a long time hippomock user and promoter.
Thius problem is still present on current master branch w/ gcc-4.8
I know this problem is still present right now, but I'm not sure how to fix it. Any ideas?
I've a test case for a function with functional argument
It worked fine with g++ 4.8.0 g++ -std=c++11 main.cpp // works fine
but printed errors while I compiled it with MS 2010
the error is