Opened 8 years ago
Closed 8 years ago
#11028 closed Bugs (duplicate)
Overloading ambiguity between basic_string & insert(0,...) and iterator insert(0,...)
Reported by: | anonymous | Owned by: | John Maddock |
---|---|---|---|
Milestone: | To Be Determined | Component: | multiprecision |
Version: | Boost 1.57.0 | Severity: | Problem |
Keywords: | Cc: |
Description
- 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.
- 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.
- 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.