Boost C++ Libraries: Ticket #4073: <boost/function/function_template.hpp> compile errors with Visual Studio 2010 - mem_fn ADL issue https://svn.boost.org/trac10/ticket/4073 <p> <strong>Problem:</strong> Using boost::function in Microsoft Visual Studio 2010 can cause an argument-dependent name lookup problem when given arguments that include std:: components. I <em>believe</em> this will happen with any compiler that has mem_fn in the std:: namespace, but have only verified it on VS 2010. </p> <p> <strong>Solution:</strong> Change two instances of mem_fn in function_template.hpp (lines 539 and 552 of the current Subversion checkout) to prefix them with the boost:: namespace qualifier. It appears that this is already done at the other two mem_fn calls at lines 207 &amp; 225. </p> <p> <strong>How to Reproduce</strong> Build the following code with Visual Studio 2010: </p> <pre class="wiki">#include &lt;boost/function.hpp&gt; #include &lt;string&gt; class PrimitiveBuilder { public: bool someFunction( std::string&amp; token ); void registerSomeFunction() { mPrimitiveFunctor = &amp;PrimitiveBuilder::someFunction; // ambiguity error is here } private: typedef boost::function&lt;bool (PrimitiveBuilder*, std::string&amp; token)&gt; PrimitiveFunctor; PrimitiveFunctor mPrimitiveFunctor; }; </pre><p> It will produce the following error message: </p> <pre class="wiki">1&gt;e:\stellar\controlled\trunk\3rdparty\boost\boost\function\function_template.hpp(539): error C2668: 'boost::mem_fn' : ambiguous call to overloaded function 1&gt; e:\stellar\controlled\trunk\3rdparty\boost\boost\bind\mem_fn_cc.hpp(25): could be 'boost::_mfi::mf1&lt;R,T,A1&gt; boost::mem_fn&lt;bool,PrimitiveBuilder,std::string&amp;&gt; (R (__thiscall PrimitiveBuilder::* )(A1))' 1&gt; with 1&gt; [ 1&gt; R=bool, 1&gt; T=PrimitiveBuilder, 1&gt; A1=std::string &amp; 1&gt; ] 1&gt; c:\program files (x86)\microsoft visual studio 10.0\vc\include\xxmem_fn(32): or 'std::tr1::_Mem_fn2&lt;_Rx,_Pmf,_Arg0,_Arg1&gt; std::tr1::mem_fn&lt;bool,PrimitiveBuilder,std::string&amp;&gt; (_Rx (__thiscall PrimitiveBuilder::* )(_Arg1))' [found using argument-dependent lookup] 1&gt; with 1&gt; [ 1&gt; _Rx=bool, 1&gt; _Pmf=bool (__thiscall PrimitiveBuilder::* )(std::string &amp;), 1&gt; _Arg0=PrimitiveBuilder, 1&gt; _Arg1=std::string &amp; 1&gt; ] 1&gt; while trying to match the argument list '(bool (__thiscall PrimitiveBuilder::* )(std::string &amp;))' </pre><p> <strong>More problem explanation</strong> Deep inside of boost there's a call to "this-&gt;assign_to_a(mem_fn(f), functor, a);". mem_fn used to be unambiguous, but now because one of our function's arguments is an std::string, the new std::mem_fn is introduced as a candidate. I verified that if I change std::string to int in the above example, the code compiles fine. I've also verified that the solution - adding "boost::" in front of the two unqualified mem_fn calls - resolved the problem. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4073 Trac 1.4.3 Conrad Poelman <cpboost@…> Wed, 28 Apr 2010 23:39:22 GMT attachment set https://svn.boost.org/trac10/ticket/4073 https://svn.boost.org/trac10/ticket/4073 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">function_template_for_c++0x.patch</span> </li> </ul> <p> Patch file with the fix </p> Ticket Jeremiah Willcock Wed, 09 Jun 2010 00:51:43 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4073#comment:1 https://svn.boost.org/trac10/ticket/4073#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/62623" title="Applied patch from #4073; fixes #4073">[62623]</a>) Applied patch from <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4073" title="#4073: Bugs: &lt;boost/function/function_template.hpp&gt; compile errors with Visual ... (closed: fixed)">#4073</a>; fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4073" title="#4073: Bugs: &lt;boost/function/function_template.hpp&gt; compile errors with Visual ... (closed: fixed)">#4073</a> </p> Ticket alexander.limubei.kasper@… Thu, 21 Oct 2010 09:02:01 GMT <link>https://svn.boost.org/trac10/ticket/4073#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4073#comment:2</guid> <description> <p> It seems this fix didn't make it into the official distributions. 1.43 and 1.44 do not contain this. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 01 Dec 2010 11:07:56 GMT</pubDate> <title>status, version changed; resolution, milestone deleted https://svn.boost.org/trac10/ticket/4073#comment:3 https://svn.boost.org/trac10/ticket/4073#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.42.0</span> → <span class="trac-field-new">Boost 1.44.0</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-deleted">Boost 1.43.0</span> </li> </ul> <p> I'm also seeing this problem with 1.44. The supplied patch seems to fix it, but needs to be applied in the released library. </p> Ticket anonymous Sat, 22 Jan 2011 06:38:14 GMT version changed https://svn.boost.org/trac10/ticket/4073#comment:4 https://svn.boost.org/trac10/ticket/4073#comment:4 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.44.0</span> → <span class="trac-field-new">Boost 1.45.0</span> </li> </ul> <p> This is also present in 1.45. The supplied patch fixes it in 1.45 as well. </p> Ticket anonymous Sun, 27 Feb 2011 07:26:09 GMT version changed https://svn.boost.org/trac10/ticket/4073#comment:5 https://svn.boost.org/trac10/ticket/4073#comment:5 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.45.0</span> → <span class="trac-field-new">Boost 1.46.0</span> </li> </ul> <p> Reported in 1.42 </p> <p> Present in: 1.42, 1.43, 1.44, 1.45 </p> <p> Still present in 1.46 </p> <p> The supplied fix for 1.42 still works, please apply it to the released version. </p> Ticket Daniel James Sun, 27 Feb 2011 08:27:35 GMT owner, status changed https://svn.boost.org/trac10/ticket/4073#comment:6 https://svn.boost.org/trac10/ticket/4073#comment:6 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Douglas Gregor</span> to <span class="trac-author">Daniel James</span> </li> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">new</span> </li> </ul> <p> Seems to be fixed on trunk but not in the release branch. I'll look into merging outstanding function changes once the release cycle starts. </p> Ticket Daniel James Sun, 27 Feb 2011 08:27:51 GMT status changed https://svn.boost.org/trac10/ticket/4073#comment:7 https://svn.boost.org/trac10/ticket/4073#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Daniel James Sun, 27 Feb 2011 08:29:49 GMT milestone set https://svn.boost.org/trac10/ticket/4073#comment:8 https://svn.boost.org/trac10/ticket/4073#comment:8 <ul> <li><strong>milestone</strong> → <span class="trac-field-new">Boost 1.47.0</span> </li> </ul> Ticket Daniel James Mon, 21 Mar 2011 21:32:44 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4073#comment:9 https://svn.boost.org/trac10/ticket/4073#comment:9 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/70361" title="Function: Merge from trunk. - Remove extra definition of operator(), ...">[70361]</a>) Function: Merge from trunk. </p> <ul><li>Remove extra definition of operator(), since it's inline anyway. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4765" title="#4765: Bugs: function_template.hpp incorrect placement of inline keyword (closed: fixed)">#4765</a>. </li><li>Make sure that the cv flags are copied when we copy a reference to a function object. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4325" title="#4325: Bugs: boost::function target method fails after copy constructing a function ... (closed: fixed)">#4325</a> </li><li>Fully qualified function calls to avoid ambiguity with new additions to standard. Thanks to Conrad Poelman. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4073" title="#4073: Bugs: &lt;boost/function/function_template.hpp&gt; compile errors with Visual ... (closed: fixed)">#4073</a> </li><li>Remove iterator workaround for newer versions of Visual Age C++. Thanks to 'ccambly'. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3912" title="#3912: Bugs: Boost.Function function30 with vacpp on AIX (closed: fixed)">#3912</a> </li><li>Fix unused variable warning for Visual C++. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3618" title="#3618: Patches: MSVC Warning suppression fix (closed: fixed)">#3618</a> </li><li>Testing flag for Visual C++. </li><li>Removed all but one old-style cast, prevents GCC warnings, but breaks GCC 2.95.3. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3410" title="#3410: Bugs: Warnings in Boost::function when compiled with &#34;-Wold-style-cast&#34; (closed: fixed)">#3410</a> </li><li>Fixed tab and newline issues from inspection report. </li></ul> Ticket