You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Arch Linux, boost 1.81.0-3, gcc version 12.2.1 20230201, clang version 15.0.7
It fails to compile on GCC and Clang at BOOST_LOG_TRIVIAL and BOOST_LOG lines due to missing overload:
/usr/include/boost/log/utility/formatting_ostream.hpp:929:19: error: no match for ‘operator<<’ (operand types are ‘boost::log::v2_mt_posix::basic_formatting_ostream::ostream_type’ {aka ‘std::basic_ostream’} and ‘test::A’)
929 | strm.stream() << value;
But when I move definition of operator<<() into namespace test, it magically fixes itself. std::clog line works well in both cases. Is this intentional behavior or a bug in boost::log? I've stumbled upon this problem when tried to output Poco::Net::SocketAddress into BOOST_LOG_TRIVIAL because it declares it's overloaded operator<<() in a global scope and not in a scope of SocketAddress.
This behavior is intended and by design. The operator<< for the class A must be findable using ADL, meaning it should probably be defined in namespace test.
The fact that it works with std::clog is because the operator is visible from the context of the streaming expression. With Boost.Log, the operator<< you're calling from the streaming expression is not the one you declared in the global namespace but one of the forwarding operators provided by Boost.Log in its namespace. These forwarding operators shadow the operator<< in the global namespace, and ADL does not find it either as it is not in any of the associated namespaces.
The code in your example is rather fragile because it can easily break due to the operator being shadowed by other operators defined for other types. Here's an example.
BOOST_LOG_TRIVIAL and BOOST_LOG behavior seems not to be equivalent to
std::cout
and other standard iostreams. Here is an example:main.cpp:
meson.build:
build:
Arch Linux, boost 1.81.0-3, gcc version 12.2.1 20230201, clang version 15.0.7
It fails to compile on GCC and Clang at BOOST_LOG_TRIVIAL and BOOST_LOG lines due to missing overload:
But when I move definition of
operator<<()
into namespacetest
, it magically fixes itself.std::clog
line works well in both cases. Is this intentional behavior or a bug in boost::log? I've stumbled upon this problem when tried to outputPoco::Net::SocketAddress
into BOOST_LOG_TRIVIAL because it declares it's overloadedoperator<<()
in a global scope and not in a scope of SocketAddress.https://github.com/pocoproject/poco/blob/1211613642269b7d53bea58b02de7fcd25ece3b9/Net/include/Poco/Net/SocketAddress.h#L304
The text was updated successfully, but these errors were encountered: