[Boost-bugs] [Boost C++ Libraries] #11029: Overloading ambiguity between basic_string & insert(0, ...) and iterator insert(0, ...)

Subject: [Boost-bugs] [Boost C++ Libraries] #11029: Overloading ambiguity between basic_string & insert(0, ...) and iterator insert(0, ...)
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-02-15 23:40:51


#11029: Overloading ambiguity between basic_string & insert(0,...) and iterator
insert(0,...)
------------------------------+----------------------------
 Reporter: sergey.sprogis@… | Owner: johnmaddock
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: multiprecision
  Version: Boost 1.57.0 | Severity: Problem
 Keywords: |
------------------------------+----------------------------
 1. Description of the failure

 Let's consider the following 7 line t.cc test:


 #include <string>

 #include <iostream>

 int main() {

  std::string s;

  s.insert(0, 1, '1');

  std::cout << s << std::endl;

 }

 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


 "l.cc", line 6: Error: Overloading ambiguity between

 "std::string::insert(char*, unsigned, char)" and

 "std::string::insert(unsigned, unsigned, char)".

 The similar code containing

   <id>.insert(0,<integer>,'<character>');

 exist in the following 7 headers of multiprecision library:


  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


 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.

  2. Cause of the failure.

 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:

   basic_string& insert(size_type pos, size_type n, charT c);

   iterator insert(const_iterator p, size_type n, charT c);

 Unfortunately, iterator for strings in stlport4 is implemented as 'char *'
 and that causes
 the following call to match both of these insert functions:

    insert(0, 1, '1');

 That happens because 0 is a valid value both for 'size_type' and
 'iterator'.
 And that naturally leads to the compilation failure shown above.

 So its not a compiler problem but rather incompatibility between Boost
 sources and these STLs.

   3. Possible Solution.

 To replace all lines:

 <id>.insert(0,<integer>,'<character>');

 with:

 <id>.insert(std::string::size_type(0)<integer>,'<character>');

 in 7 boost header files listed above.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11029>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:17 UTC