|
Boost Users : |
From: Leo Carreon (lcarreon_at_[hidden])
Date: 2020-03-09 03:58:47
Hi Mateusz,
Here is the information you requested.
When the following test is performed using Boost.Test:
auto string_1 = u8"sample"s; // variable initialized with std::u8string
literal
auto string_2 = u8"sample"sv; // variable initialized with
std::u8string_view literal
BOOST_TEST(string_1 == string_2);
The compilation fails with an error message similar to this:
In file included from /usr/include/c++/9/string:55,
from /usr/include/c++/9/bits/locale_classes.h:40,
from /usr/include/c++/9/bits/ios_base.h:41,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/istream:38,
from /usr/include/c++/9/sstream:38,
from src/test_description.cpp:9:
/usr/include/c++/9/bits/basic_string.h: In instantiation of âclass
std::__cxx11::basic_string<const char8_t, std::char_traits<const char8_t>,
std::allocator<const char8_t> >â:
/usr/local/include/boost/test/tools/cstring_comparison_op.hpp:75:1:
required from âstatic bool boost::test_tools::assertion::op::EQ<Lhs, Rhs,
typename
boost::enable_if_c<(boost::unit_test::is_cstring_comparable<Lhs>::value &&
boost::unit_test::is_cstring_comparable<Rhs>::value)>::type>::eval(const
Lhs&, const Rhs&) [with Lhs = std::__cxx11::basic_string<char8_t>; Rhs =
std::basic_string_view<char8_t>]â
/usr/local/include/boost/test/tools/assertion.hpp:354:24: required from
âboost::test_tools::assertion::binary_expr<Lhs, Rhs, OP>::result_type
boost::test_tools::assertion::binary_expr<Lhs, Rhs, OP>::value() const [with
LExpr =
boost::test_tools::assertion::value_expr<std::__cxx11::basic_string<char8_t>
>; Rhs = const std::basic_string_view<char8_t>&; OP =
boost::test_tools::assertion::op::EQ<std::__cxx11::basic_string<char8_t>,
std::basic_string_view<char8_t>, void>;
boost::test_tools::assertion::binary_expr<Lhs, Rhs, OP>::result_type =
boost::test_tools::assertion_result]â
/usr/local/include/boost/test/tools/assertion.hpp:363:42: required from
âboost::test_tools::assertion_result
boost::test_tools::assertion::binary_expr<Lhs, Rhs, OP>::evaluate(bool)
const [with LExpr =
boost::test_tools::assertion::value_expr<std::__cxx11::basic_string<char8_t>
>; Rhs = const std::basic_string_view<char8_t>&; OP =
boost::test_tools::assertion::op::EQ<std::__cxx11::basic_string<char8_t>,
std::basic_string_view<char8_t>, void>]â
src/test_description.cpp:50:2: required from here
Is there a possible workaround other than doing this:
BOOST_TEST((string_1 == string_2));
Note that I have provided the following functions to allow the printing of
std::u8string, std::u8string_view and char8_t*:
std::ostream& std::operator<<(std::ostream&, std::u8string_view);
std::ostream& std::operator<<(std::ostream&, const char8_t*);
To allow the printing of the compared values.
BTW, Boost.Test seems to be happy with the following test:
auto string_1 = u8"sample"s; // this creates a std::u8string variable
auto string_2 = u8"sample"; // this creates a const char8_t* variable
BOOST_TEST(string_1 == string_2);
-----Original Message-----
From: Mateusz Loskot via Boost-users
Sent: Sunday, March 8, 2020 11:51 AM
To: boost-users_at_[hidden]
Cc: Mateusz Loskot
Subject: Re: [Boost-users] Boost.Test failing to compare std::basic_string
strings
On Sun, 8 Mar 2020 at 01:06, Leo Carreon via Boost-users
<boost-users_at_[hidden]> wrote:
>
> Hi Boost.Users,
>
> Iâm using Boost.Test from Boost 1.72.0 and Iâm getting a failure when I
> perform the following test:
>
> auto string_1 = u8âvalueâs;
> auto string_2 = u8âvalueâs;
> BOOST_TEST(string_1 == string_2);
If you are getting a failure, tell what is the failure (crystal
spheres not always work ;))
I suspect you are hitting two issues:
1. std::u8string is not "eligible for string comparison"
https://www.boost.org/libs/test/doc/html/boost_test/testing_tools/extended_comparison/strings.html
2. reporting of char8_t falls into reporting of user-defined type
https://www.boost.org/libs/test/doc/html/boost_test/test_output/test_tools_support_for_logging/testing_tool_output_disable.html
A possible hack to work around these two could be
namespace std {
std::ostream& boost_test_print_type(std::ostream& os, char8_t const& c)
{
// convert c
return os;
}
}
BOOST_TEST(string_1 == string_2, boost::test_tools::per_element());
> However, the problem goes away when I change the test line to:
>
> BOOST_TEST((string_1 == string_2));
>
> What is the reason why Boost.Test is failing without the double
> parentheses?
It disables (de)constructing of the expression from macro input, see
https://www.boost.org/libs/test/doc/html/boost_test/testing_tools/internal_details.html
https://www.boost.org/libs/test/doc/html/boost_test/testing_tools/boost_test_universal_macro.html
Best regards,
-- Mateusz Loskot, http://mateusz.loskot.net _______________________________________________ Boost-users mailing list Boost-users_at_[hidden] https://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net