opentelemetry-cpp icon indicating copy to clipboard operation
opentelemetry-cpp copied to clipboard

Fails to compile WITH_STL in gcc 7.3.1 for arm-v7a-linux-gnueabihf, ambiguous overload in variant.

Open jan-hudec opened this issue 4 years ago • 6 comments
trafficstars

Describe your environment

arm-v7a-linux-gnueabihf g++ 7.3.1, OSELAS build build environment set up with ptxdist 2019.01.0 toolchain oselas.toolchain-2018.02.0-arm-v7a-linux-gnueabihf-gcc-7.3.1-glibc-2.27-binutils-2.30-kernel-4.15-sanitized from pengutronix repo.

Steps to reproduce

Created a standard package for opentelemetry-cpp using version 1.0.1. Configure options set to

OPENTELEMETRY_CPP_CONF_OPT	:= $(CROSS_CMAKE_USR) \
				   -DWITH_STL=ON \
				   -DBUILD_TESTING=OFF \
				   -DWITH_EXAMPLES=OFF \
				   -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

The potential client code is full C++17 with full standard library utilization, so we want to use standard library.

I did install nlohman-json (via separate package, using version 3.9.1 that corresponds the git submodule reference) into the cross-compilation sysroot.

What is the expected behavior?

Compile the SDK.

What is the actual behavior?

Compilation fails with following errors:

[ 47%] Building CXX object sdk/src/resource/CMakeFiles/opentelemetry_resources.dir/resource_detector.cc.o
In file included from ../../../../opentelemetry-cpp-1.0.1/api/include/opentelemetry/std/string_view.h:14:0,
                 from ../../../../opentelemetry-cpp-1.0.1/api/include/opentelemetry/nostd/string_view.h:7,
                 from ../../../../opentelemetry-cpp-1.0.1/api/include/opentelemetry/common/attribute_value.h:9,
                 from ../../../../opentelemetry-cpp-1.0.1/sdk/include/opentelemetry/sdk/resource/resource.h:6,
                 from ../../../../opentelemetry-cpp-1.0.1/sdk/src/resource/resource_detector.cc:6:
/opt/OSELAS.Toolchain-2018.02.0/arm-v7a-linux-gnueabihf/gcc-7.3.1-glibc-2.27-binutils-2.30-kernel-4.15-sanitized/arm-v7a-linux-gnueabihf/include/c++/7.3.1/variant: In instantiation of 'constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = opentelemetry::v1::sdk::common::AttributeConverter&; _Variants = {const std::variant<bool, int, long long int, unsigned int, double, const char*, std::basic_string_view<char, std::char_traits<char> >, opentelemetry::v1::nostd::span<const bool, 4294967295>, opentelemetry::v1::nostd::span<const int, 4294967295>, opentelemetry::v1::nostd::span<const long long int, 4294967295>, opentelemetry::v1::nostd::span<const unsigned int, 4294967295>, opentelemetry::v1::nostd::span<const double, 4294967295>, opentelemetry::v1::nostd::span<const std::basic_string_view<char, std::char_traits<char> >, 4294967295>, long long unsigned int, opentelemetry::v1::nostd::span<const long long unsigned int, 4294967295>, opentelemetry::v1::nostd::span<const unsigned char, 4294967295> >&}]':
../../../../opentelemetry-cpp-1.0.1/api/include/opentelemetry/std/variant.h:198:45:   required from 'constexpr auto opentelemetry::v1::nostd::visit(_Callable&&, _Variants&& ...) [with _Callable = opentelemetry::v1::sdk::common::AttributeConverter&; _Variants = {const std::variant<bool, int, long long int, unsigned int, double, const char*, std::basic_string_view<char, std::char_traits<char> >, opentelemetry::v1::nostd::span<const bool, 4294967295>, opentelemetry::v1::nostd::span<const int, 4294967295>, opentelemetry::v1::nostd::span<const long long int, 4294967295>, opentelemetry::v1::nostd::span<const unsigned int, 4294967295>, opentelemetry::v1::nostd::span<const double, 4294967295>, opentelemetry::v1::nostd::span<const std::basic_string_view<char, std::char_traits<char> >, 4294967295>, long long unsigned int, opentelemetry::v1::nostd::span<const long long unsigned int, 4294967295>, opentelemetry::v1::nostd::span<const unsigned char, 4294967295> >&}]'
../../../../opentelemetry-cpp-1.0.1/sdk/include/opentelemetry/sdk/common/attribute_utils.h:140:63:   required from here
/opt/OSELAS.Toolchain-2018.02.0/arm-v7a-linux-gnueabihf/gcc-7.3.1-glibc-2.27-binutils-2.30-kernel-4.15-sanitized/arm-v7a-linux-gnueabihf/include/c++/7.3.1/variant:1243:12: error: call of overloaded 'get<0>(const std::variant<bool, int, long long int, unsigned int, double, const char*, std::basic_string_view<char, std::char_traits<char> >, opentelemetry::v1::nostd::span<const bool, 4294967295>, opentelemetry::v1::nostd::span<const int, 4294967295>, opentelemetry::v1::nostd::span<const long long int, 4294967295>, opentelemetry::v1::nostd::span<const unsigned int, 4294967295>, opentelemetry::v1::nostd::span<const double, 4294967295>, opentelemetry::v1::nostd::span<const std::basic_string_view<char, std::char_traits<char> >, 4294967295>, long long unsigned int, opentelemetry::v1::nostd::span<const long long unsigned int, 4294967295>, opentelemetry::v1::nostd::span<const unsigned char, 4294967295> >&)' is ambiguous
      get<0>(std::forward<_Variants>(__variants))...));
      ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/OSELAS.Toolchain-2018.02.0/arm-v7a-linux-gnueabihf/gcc-7.3.1-glibc-2.27-binutils-2.30-kernel-4.15-sanitized/arm-v7a-linux-gnueabihf/include/c++/7.3.1/variant:1214:5: note: candidate: constexpr std::variant_alternative_t<_Np, std::variant<_Types ...> >& std::get(const std::variant<_Types ...>&) [with unsigned int _Np = 0; _Types = {bool, int, long long int, unsigned int, double, const char*, std::basic_string_view<char, std::char_traits<char> >, opentelemetry::v1::nostd::span<const bool, 4294967295>, opentelemetry::v1::nostd::span<const int, 4294967295>, opentelemetry::v1::nostd::span<const long long int, 4294967295>, opentelemetry::v1::nostd::span<const unsigned int, 4294967295>, opentelemetry::v1::nostd::span<const double, 4294967295>, opentelemetry::v1::nostd::span<const std::basic_string_view<char, std::char_traits<char> >, 4294967295>, long long unsigned int, opentelemetry::v1::nostd::span<const long long unsigned int, 4294967295>, opentelemetry::v1::nostd::span<const unsigned char, 4294967295>}; std::variant_alternative_t<_Np, std::variant<_Types ...> > = bool]
     get(const variant<_Types...>& __v)
     ^~~
In file included from ../../../../opentelemetry-cpp-1.0.1/api/include/opentelemetry/nostd/variant.h:9:0,
                 from ../../../../opentelemetry-cpp-1.0.1/api/include/opentelemetry/common/attribute_value.h:10,
                 from ../../../../opentelemetry-cpp-1.0.1/sdk/include/opentelemetry/sdk/resource/resource.h:6,
                 from ../../../../opentelemetry-cpp-1.0.1/sdk/src/resource/resource_detector.cc:6:
../../../../opentelemetry-cpp-1.0.1/api/include/opentelemetry/std/variant.h:158:72: note: candidate: constexpr std::variant_alternative_t<_Np, std::variant<_Types ...> >& opentelemetry::v1::nostd::get(const std::variant<_Types ...>&) [with unsigned int I = 0; Types = {bool, int, long long int, unsigned int, double, const char*, std::basic_string_view<char, std::char_traits<char> >, opentelemetry::v1::nostd::span<const bool, 4294967295>, opentelemetry::v1::nostd::span<const int, 4294967295>, opentelemetry::v1::nostd::span<const long long int, 4294967295>, opentelemetry::v1::nostd::span<const unsigned int, 4294967295>, opentelemetry::v1::nostd::span<const double, 4294967295>, opentelemetry::v1::nostd::span<const std::basic_string_view<char, std::char_traits<char> >, 4294967295>, long long unsigned int, opentelemetry::v1::nostd::span<const long long unsigned int, 4294967295>, opentelemetry::v1::nostd::span<const unsigned char, 4294967295>}; std::variant_alternative_t<_Np, std::variant<_Types ...> > = bool]
 constexpr const std::variant_alternative_t<I, std::variant<Types...>> &get(
                                                                        ^~~

The error appears twice, and then there is a bunch of follow-up errors caused by the fact that the first error is in deducing the return type of the visit and the compiler just tries to use void to recover.

Additional context

The first error (appears twice) indicates ambiguity between the std::get function and the nostd::get that forwards to it, the later being found with argument-dependent lookup because while variant itself is imported into the nostd namespace with using, the get functions are defined as wrappers, so there are two versions of the later when std::visit tries to call it.

Since other parts are being pulled with using, would it be possible to pull the std::get into nostd in the same way?

Gcc 9 and 10 have that part changed to call std::get explicitly, so it won't have the same problem. Unfortunately for embedded development it is not that easy to just update the toolchain.

jan-hudec avatar Nov 18 '21 15:11 jan-hudec

… I remembered it didn't compile without the WITH_STL=ON either, but that is actually only in examples, so WITH_EXAMPLES=OFF plus WITH_STL=OFF does compile. I didn't test any of the exporters yet, but in this stage I'll need a custom exporter anyway, so I can live without them.

jan-hudec avatar Nov 18 '21 15:11 jan-hudec

I don't see the gcc-7.3.1 toolchain available for ubuntu to validate, fix and test this issue. And build doesn't fail with gcc-7.5.0. Have tagged this issue for help.

lalitb avatar Dec 02 '21 07:12 lalitb

It is not from Ubuntu, it is a cross-compilation toolchain from Pengutronix. The apt sources line is

deb http://debian.pengutronix.de/debian/ bionic main contrib non-free

and the package to install is

oselas.toolchain-2018.02.0-arm-v7a-linux-gnueabihf-gcc-7.3.1-glibc-2.27-binutils-2.30-kernel-4.15-sanitized

jan-hudec avatar Dec 02 '21 09:12 jan-hudec

This issue was marked as stale due to lack of activity. It will be closed in 7 days if no furthur activity occurs.

github-actions[bot] avatar Mar 09 '22 01:03 github-actions[bot]

I gave up on the library, because my first attempt at using it promptly crashed. I don't care any more.

jan-hudec avatar Mar 09 '22 15:03 jan-hudec

I gave up on the library, because my first attempt at using it promptly crashed. I don't care any more.

Sorry for your experience. Issue has been tagged as help wanted as error is happening with specific toolchain, and not widely reported. Contributions are welcome to debug and fix the issue.

lalitb avatar Mar 09 '22 15:03 lalitb

Thanks for the initial report and investigations.

From the previous comments, in particular:

Gcc 9 and 10 have that part changed to call std::get explicitly, so it won't have the same problem. Unfortunately for embedded development it is not that easy to just update the toolchain.

It seems (not confirmed) that the original issue was in the gcc headers.

Gcc 7.3.1 + opentelemetry-1.0.1 is very old by now.

Realistically, the best course of action at this point is to use more recent dependencies and build again, to get a clearer picture.

Closing this issue.

Should the problem still exist, please reopen the report and paste recent logs.

marcalff avatar Jun 20 '23 15:06 marcalff