Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#12969 closed Bugs (fixed)

Problem linking print_helper_t<nullptr_t> under Clang

Reported by: Tony Lewis <TonyELewis@…> Owned by: Raffi Enficiaud
Milestone: Boost 1.67.0 Component: test
Version: Boost 1.64.0 Severity: Problem
Keywords: test, link, print_helper_t, nullptr, nullptr_t, 1_64_0_b2 Cc:

Description

I'm trying out 1.64.0 b2...

I can get the following code to compile, link and run under GCC :

#define BOOST_TEST_DYN_LINK

#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE( plv_tc ) {
        BOOST_TEST( nullptr == nullptr );
}

bool init_function() { return true; }
int main( int argc, char* argv[] ) {
        return ::boost::unit_test::unit_test_main( &init_function, argc, argv );
}

...with commands:

setenv BOOST_ROOT /opt/boost_1_64_0_b2_gcc_build
setenv LD_LIBRARY_PATH $BOOST_ROOT/lib
g++ -std=c++11 -isystem $BOOST_ROOT/include boost-test.nullptr-problem.cpp -L$BOOST_ROOT/lib -lboost_unit_test_framework-mt
./a.out

...but if I try with Clang:

setenv BOOST_ROOT /opt/boost_1_64_0_b2_clang_build
setenv LD_LIBRARY_PATH $BOOST_ROOT/lib
clang++ -std=c++11 -stdlib=libc++ -isystem $BOOST_ROOT/include boost-test.nullptr-problem.cpp -L$BOOST_ROOT/lib -lboost_unit_test_framework-mt

...I get:

/tmp/boost-test-fe7931.o: In function `std::__1::basic_ostream<char, std::__1::char_traits<char> >& boost::test_tools::tt_detail::operator<< <decltype(nullptr)>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, boost::test_tools::tt_detail::print_helper_t<decltype(nullptr)> const&)':
boost-test.nullptr-problem.cpp:(.text._ZN5boost10test_tools9tt_detaillsIDnEERNSt3__113basic_ostreamIcNS3_11char_traitsIcEEEES8_RKNS1_14print_helper_tIT_EE[_ZN5boost10test_tools9tt_detaillsIDnEERNSt3__113basic_ostreamIcNS3_11char_traitsIcEEEES8_RKNS1_14print_helper_tIT_EE]+0x26): undefined reference to `boost::test_tools::tt_detail::print_log_value<decltype(nullptr)>::operator()(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, decltype(nullptr))'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I may well just be doing something stupid - apologies if so.

I'm using Clang++ 3.8.1 and GCC 6.2.0 on Ubuntu 16.10 (Linux 4.8.0-46-generic; x86_64).

Change History (9)

comment:1 by Raffi Enficiaud, 6 years ago

Owner: changed from Gennadiy Rozental to Raffi Enficiaud
Status: newassigned

comment:2 by Tony E Lewis <TonyELewis@…>, 5 years ago

AFAUI, what's going on is:

  • I'm building my code in C++14 mode, which causes the Boost Test code to provide a specialisation of print_log_value<> for nullptr_t with a declaration (but not definition) of its operator().
  • I'm linking against Boost libraries that were built without any standard specified. In GCC 7.2.0 means ~C++14 but in Clang 4.0.1 means ~C++03. So the Clang-built library I'm linking against doesn't provide any definition of print_log_value<std::nullptr_t>::operator().

I can work around this. However it may make things a bit simpler to either:

  • provide an inline definition of print_log_value<std::nullptr_t>::operator() in the .hpp rather than in a separate .ipp, or failing that
  • not specialise print_log_value<> for nullptr_t at all and leave it for users to do themselves if they wish.

comment:3 by Raffi Enficiaud, 5 years ago

Thanks, I was not able to reproduce initially the issue, but with the last information I understand better what the issue is.

comment:4 by Raffi Enficiaud, 5 years ago

In branch topic/12969-problems-nullptr. It would be good if you tell me if this fixes your issue, as it is not possible to have a unit test covering this.

comment:5 by Raffi Enficiaud, 5 years ago

Milestone: To Be DeterminedBoost 1.66.0

comment:6 by Raffi Enficiaud, 5 years ago

Milestone: Boost 1.66.0Boost 1.67.0

comment:7 by Raffi Enficiaud, 5 years ago

On develop

comment:8 by Raffi Enficiaud, 5 years ago

Resolution: fixed
Status: assignedclosed

On master

comment:9 by Tony E Lewis <tonyelewis@…>, 5 years ago

Thanks very much for this fix.

Apologies - I didn't see the message asking for a check. Yes - that works for me.

Note: See TracTickets for help on using tickets.