Boost C++ Libraries: Ticket #11029: Overloading ambiguity between basic_string & insert(0,...) and iterator insert(0,...) https://svn.boost.org/trac10/ticket/11029 <ol><li>Description of the failure </li></ol><p> Let's consider the following 7 line t.cc test: </p> <p> #include &lt;string&gt; </p> <p> #include &lt;iostream&gt; </p> <p> int main() { </p> <blockquote> <p> std::string s; </p> </blockquote> <blockquote> <p> s.insert(0, 1, '1'); </p> </blockquote> <blockquote> <p> std::cout &lt;&lt; s &lt;&lt; std::endl; </p> </blockquote> <p> } </p> <p> Its complation on Solaris 11.2 with Oracle Studio 12.4 C++ compiler using -library=stlport4 option (which tells compiler to use STL Standard library) produces the following error messages </p> <p> "l.cc", line 6: Error: Overloading ambiguity between </p> <p> "std::string::insert(char*, unsigned, char)" and </p> <p> "std::string::insert(unsigned, unsigned, char)". </p> <p> The similar code containing </p> <blockquote> <p> &lt;id&gt;.insert(0,&lt;integer&gt;,'&lt;character&gt;'); </p> </blockquote> <p> exist in the following 7 headers of multiprecision library: </p> <blockquote> <p> multiprecision/tommath.hpp, multiprecision/cpp_dec_float.hpp, multiprecision/cpp_bin_float/io.hpp, multiprecision/cpp_int.hpp, multiprecision/number.hpp, multiprecision/detail/number_base.hpp, multiprecision/detail/float_string_cvt.hpp </p> </blockquote> <p> which is the reason for numerous compilation failures in regression unit tests of multiprecision library when any of 3 Standard librarries (Apache, STL, RW) are used with Studio 12.4 C++ compiler. </p> <ol start="2"><li>Cause of the failure. </li></ol><p> This failure is a direct consequence of STL implementation detail for string iterators. C++ standard requires STL to provide the following string::insert member functions: </p> <blockquote> <p> basic_string&amp; insert(size_type pos, size_type n, charT c); </p> </blockquote> <blockquote> <p> iterator insert(const_iterator p, size_type n, charT c); </p> </blockquote> <p> Unfortunately, iterator for strings in stlport4 is implemented as 'char *' and that causes the following call to match both of these insert functions: </p> <blockquote> <p> insert(0, 1, '1'); </p> </blockquote> <p> That happens because 0 is a valid value both for 'size_type' and 'iterator'. And that naturally leads to the compilation failure shown above. </p> <p> So its not a compiler problem but rather incompatibility between Boost sources and these STLs. </p> <ol start="3"><li>Possible Solution. </li></ol><p> To replace all lines: </p> <p> &lt;id&gt;.insert(0,&lt;integer&gt;,'&lt;character&gt;'); </p> <p> with: </p> <p> &lt;id&gt;.insert(std::string::size_type(0)&lt;integer&gt;,'&lt;character&gt;'); </p> <p> in 7 boost header files listed above. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11029 Trac 1.4.3 John Maddock Sun, 22 Feb 2015 13:24:19 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11029#comment:1 https://svn.boost.org/trac10/ticket/11029#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">duplicate</span> </li> </ul> <p> Duplicates 11028. </p> Ticket John Maddock Sun, 22 Feb 2015 13:25:08 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/11029#comment:2 https://svn.boost.org/trac10/ticket/11029#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">duplicate</span> </li> </ul> <p> Ah, I see the other one is the duplicate :( </p> Ticket John Maddock Sun, 22 Feb 2015 18:33:07 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11029#comment:3 https://svn.boost.org/trac10/ticket/11029#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed in <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/e175ed2bfe168fa5066b451fdc8e66479be76306"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/e175ed2bfe168fa5066b451fdc8e66479be76306</a> </p> Ticket