asio/ip/udp.hpp causes MSVC to use std::bind

boost 1.55 VS2012 Update 4 === Can you tell me why the following code fails to compile? It smells as if udp.hpp is causing MSVC to "using namespace std". PS: It doesn't happen if I remove the asio include. PPS: It doesn't happen if g() takes int vs std::string. PPPS: It doesn't happen on GCC Thank you, Chris === #include <boost/bind.hpp> #include <boost/asio/ip/udp.hpp> #include <string> using boost::bind; void g(const std::string&) { } int main() { bind(g, _1); return 0; } === 1>------ Build started: Project: OverlayServer, Configuration: Debug Win32 ------ 1> main.cpp 1>main.cpp(13): error C2668: 'std::bind' : ambiguous call to overloaded function 1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(1387): could be 'std::_Bind<_Forced,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,<unnamed-symbol>> std::bind<void,const std::string&,boost::arg<I>&>(_Rx (__cdecl *)(const std::basic_string<_Elem,_Traits,_Alloc>),_Vx0_t)' [found using argument-dependent lookup] 1> with 1> [ 1> _Forced=true, 1> _Ret=void, 1> _Fun=void (__cdecl *const )(const std::string &), 1> _V0_t=boost::arg<1> &, 1> _V1_t=std::_Nil, 1> _V2_t=std::_Nil, 1> _V3_t=std::_Nil, 1> _V4_t=std::_Nil, 1> _V5_t=std::_Nil, 1> <unnamed-symbol>=std::_Nil, 1> I=1, 1> _Rx=void, 1> _Elem=char, 1> _Traits=std::char_traits<char>, 1> _Alloc=std::allocator<char>, 1> _Vx0_t=boost::arg<1> & 1> ] 1> c:\externalpackages\boost_1_55_0\boost\bind\bind_cc.hpp(26): or 'boost::_bi::bind_t<R,F,L> boost::bind<void,const std::string&,boost::arg<I>>(R (__cdecl *)(B1),A1)' 1> with 1> [ 1> R=void, 1> F=void (__cdecl *)(const std::string &), 1> L=boost::_bi::list1<boost::arg<1>>, 1> I=1, 1> B1=const std::string &, 1> A1=boost::arg<1> 1> ] 1> while trying to match the argument list '(overloaded-function, boost::arg<I>)' 1> with 1> [ 1> I=1 1> ] ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

On 29/01/2014 07:09 p.m., Chris Stankevitz wrote:
Can you tell me why the following code fails to compile? It smells as if udp.hpp is causing MSVC to "using namespace std".
MSVC is doing some kind of weird argument dependent lookup.
PS: It doesn't happen if I remove the asio include.
That is because <functional> gets included by it. Include it directly and you should get the same error.
PPS: It doesn't happen if g() takes int vs std::string.
That is because `string` is in the `std` namespace. Change it to anything else in the `std` namespace and you should get the same error.
PPPS: It doesn't happen on GCC
This is because it's a MSVC bug. I cannot reproduce it in VS2013, so I guess they fixed it.
#include <boost/bind.hpp> #include <boost/asio/ip/udp.hpp> #include <string>
using boost::bind;
void g(const std::string&) { }
int main() { bind(g, _1); return 0; }
Regards, -- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com
participants (2)
-
Agustín K-ballo Bergé
-
Chris Stankevitz