Opened 6 years ago

#12814 new Bugs

BOOST_TEST_EQ has wrong behavior for const char*

Reported by: Hans Dembinski <hans.dembinski@…> Owned by: Peter Dimov
Milestone: To Be Determined Component: core
Version: Boost 1.61.0 Severity: Problem
Keywords: Cc:

Description

BOOST_TEST_EQ internally compares its arguments using test_eq_impl, which calls operator==. If BOOST_TEST_EQ is called with two c-strings of type const char*, it compares the addresses, not the strings.

The following fails, while it should succeed:

const char* s1 = "abc"; std::string s2("abc"); BOOST_TEST_EQ(s1, s2.c_str()); fails

Solution: Add an overload for boost::detail::test_eq_impl which compares const char* using std::strcmp.

Similarly for test_ne_impl.

Change History (0)

Note: See TracTickets for help on using tickets.