Upgrading from boost 1.76 to 1.79 caused a regression in some code I have been working on. This regression comes in the following build error:
In file included from .../boost/json/value.hpp:20,
from <list of includes>
from .../a.cpp
.../boost/json/string.hpp: In member function ‘int boost::json::string::compare(boost::json::string_view) const’:
.../boost/json/string.hpp:1948: error: call of overloaded ‘basic_string_view(const boost::json::string&)’ is ambiguous
return string_view(*this).compare(sv);
In file included from .../boost/json/string_view.hpp:14,
from <lsit of includes>
from .../a.cpp
.../boost/core/detail/string_view.hpp:391: note: candidate: ‘boost::core::basic_string_view<Ch>::basic_string_view(const std::basic_string_view<Ch, std::char_traits<_CharT> >&) [with Ch = char]’
basic_string_view( std::basic_string_view<Ch, std::char_traits<Ch> > const& str ) BOOST_NOEXCEPT: p_( str.data() ), n_( str.size() )
.../boost/core/detail/string_view.hpp:335: note: candidate: ‘constexpr boost::core::basic_string_view<char>::basic_string_view(const boost::core::basic_string_view<char>&)’
template<class Ch> class basic_string_view
.../boost/core/detail/string_view.hpp:335: note: candidate: ‘constexpr boost::core::basic_string_view<char>::basic_string_view(boost::core::basic_string_view<char>&&)’
Here is some example code that I reproduced this with: (GCC 8.2.1, std=c++17)
#include <string>
#include <boost/json.hpp>
#include <boost/json/src.hpp>
int main(int argc, char** argv)
{
return 0;
}
Note it builds with std=c++11 or c++14, however c++17 is a requirment of this project. This error only occurs on linux with GCC. This code builds on Windows with MSVC.
Are there any possible workarounds?
I have tried a couple different tricks using "using" and different namespaces but with the templating it's hard for me to to figure out what is happeneing enough to fix it. I hope I can get this working without changing JSON libraries, or with some other workaround.
Note this build error does not exist with boost 1.76.