Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.79: Build error with gcc 8 in C++17 mode: ambiguous conversion to string_view #708

Closed
Lastique opened this issue May 25, 2022 · 5 comments · Fixed by #711
Closed

1.79: Build error with gcc 8 in C++17 mode: ambiguous conversion to string_view #708

Lastique opened this issue May 25, 2022 · 5 comments · Fixed by #711

Comments

@Lastique
Copy link
Member

Version of Boost

Boost 1.79.0 release with Boost.JSON patch from release notes applied.

Steps necessary to reproduce the problem

Build Boost.JSON:

b2 -j16 -q -d2  --layout=system --ignore-site-config --user-config=/build/boost/boost_1_79_0/user-config.jam variant=release debug-symbols=on cxxstd=17-gnu numa=on link=static,shared  --without-python

This results in compiler errors like this:

gcc.compile.c++ bin.v2/libs/json/build/gcc-8/release/cxxstd-17-gnu/debug-symbols-on/link-static/numa-on/threading-multi/visibility-hidden/src.o

    "g++"   -std=gnu++17 -fvisibility-inlines-hidden -g -O2 -fdebug-prefix-map=/build/boost/boost_1_79_0=. -fstack-protector-strong -Wformat -Werror=format-security -O3 -fno-math-errno -fno-rounding-math -fno-signaling-nans -fno-trapping-math -ftree-vectorize -fgcse-sm -fgcse-las -fgcse-after-reload -ftree-loop-im -ftree-loop-distribution -ftree-loop-if-convert -funswitch-loops -frename-registers -fivopts -fvisibility-inlines-hidden -fno-plt -faligned-new -march=nehalem -mtune=skylake -Wno-unused-local-typedefs -Wno-register -Wno-deprecated-declarations -Wno-register -Wno-deprecated-declarations -pthread -O3 -finline-functions -Wno-inline -Wall -g -fvisibility=hidden -Wdate-time -D_FORTIFY_SOURCE=2  -DBOOST_ALL_NO_LIB=1 -DBOOST_CONTAINER_STATIC_LINK=1 -DBOOST_JSON_SOURCE -DBOOST_JSON_STATIC_LINK=1 -DBOOST_USE_NUMA -DNDEBUG  -I"."  -c -o "bin.v2/libs/json/build/gcc-8/release/cxxstd-17-gnu/debug-symbols-on/link-static/numa-on/threading-multi/visibility-hidden/src.o" "libs/json/src/src.cpp"

In file included from ./boost/json/value.hpp:20,
                 from ./boost/json/array.hpp:1756,
                 from ./boost/json.hpp:15,
                 from ./boost/json/src.hpp:27,
                 from libs/json/src/src.cpp:10:
./boost/json/string.hpp: In member function 'int boost::json::string::compare(boost::json::string_view) const':
./boost/json/string.hpp:1948:33: 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 ./boost/json/kind.hpp:14,
                 from ./boost/json/array.hpp:14,
                 from ./boost/json.hpp:15,
                 from ./boost/json/src.hpp:27,
                 from libs/json/src/src.cpp:10:
./boost/core/detail/string_view.hpp:391:5: 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:26: 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:26: note: candidate: 'constexpr boost::core::basic_string_view<char>::basic_string_view(boost::core::basic_string_view<char>&&)'
In file included from ./boost/json/value.hpp:20,
                 from ./boost/json/array.hpp:1756,
                 from ./boost/json.hpp:15,
                 from ./boost/json/src.hpp:27,
                 from libs/json/src/src.cpp:10:

Full build log attached:
boost-build.log

All relevant compiler information

This happens with gcc 8.3 that is shipped with Debian 10 Buster, when building in C++17 mode with GNU extensions.

@Lastique
Copy link
Member Author

I suspect, this is because the compiler considers two conversion paths:

  1. boost::json::string -> boost::core::string_view (via boost::json::string::operator string_view) -> boost::core::string_view (via boost::core::string_view(boost::core::string_view&&) constructor)
  2. boost::json::string -> std::string_view (via boost::json::string::operator std::string_view) -> boost::core::string_view (via boost::core::string_view(std::string_view const&) constructor)

I realize that the last step in the first chain is redundant and should not be needed (this is just my interpretation of the compiler error), and I agree that this is probably a compiler issue. But still, gcc 8 is fairly recent and it would be nice if it was supported.

@Lastique
Copy link
Member Author

@pdimov FYI, just in case if boost::core::string_view needs to be fixed.

@vinniefalco
Copy link
Member

It looks like gcc 8.3 fails: https://godbolt.org/z/bnd9eMEx9

But gcc 8.4 (and 8.5) works: https://godbolt.org/z/TGj1exv1v

vinniefalco added a commit to vinniefalco/json that referenced this issue May 26, 2022
@vinniefalco
Copy link
Member

This might fix it #709

@pdimov
Copy link
Member

pdimov commented May 26, 2022

All the string_view(*this) occurrences need to be changed to subview() though.

vinniefalco added a commit to vinniefalco/json that referenced this issue May 26, 2022
vinniefalco added a commit to vinniefalco/json that referenced this issue May 26, 2022
vinniefalco added a commit to vinniefalco/json that referenced this issue May 26, 2022
vinniefalco added a commit to vinniefalco/json that referenced this issue May 26, 2022
vinniefalco added a commit to vinniefalco/json that referenced this issue May 26, 2022
grisumbras pushed a commit to grisumbras/json that referenced this issue May 27, 2022
tuxillo added a commit to DragonFlyBSD/DeltaPorts that referenced this issue Jul 27, 2022
 - Build was broken for gcc 8.3, which is the one
   we use in base.
 - More details: boostorg/json#708
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants