Opened 8 years ago

Closed 8 years ago

#11029 closed Bugs (fixed)

Overloading ambiguity between basic_string & insert(0,...) and iterator insert(0,...)

Reported by: sergey.sprogis@… Owned by: John Maddock
Milestone: To Be Determined Component: multiprecision
Version: Boost 1.57.0 Severity: Problem
Keywords: Cc:

Description

  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.

  1. 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.

  1. 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.

Change History (3)

comment:1 by John Maddock, 8 years ago

Resolution: duplicate
Status: newclosed

Duplicates 11028.

comment:2 by John Maddock, 8 years ago

Resolution: duplicate
Status: closedreopened

Ah, I see the other one is the duplicate :(

comment:3 by John Maddock, 8 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.