[Test] BOOST_CHECK_EQUAL can't compare scoped enumerations

I'm running Windows 10, 64-bit, MinGW64 with GCC 5.3 64-bit, and BOOST_1_60_0 64-bit. Here is the stripped down version of what's failing: enum class UsedFor { NOTIFY_INPUT, CONST_INPUT, VAR_INPUT, NOTIFY_RESULT, VAR_RESULT}; UsedFor mUse = UsedFor::NOTIFY_INPUT; BOOST_CHECK(mUse == Operand::UsedFor::NOTIFY_INPUT); // BOOST_CHECK_EQUAL(mUse, Operand::UsedFor::NOTIFY_INPUT); If BOOST_CHECK_EQUAL() is commented out, BOOST_CHECK() complies and executes without error. However, // BOOST_CHECK(mUse == Operand::UsedFor::NOTIFY_INPUT); BOOST_CHECK_EQUAL(mUse, Operand::UsedFor::NOTIFY_INPUT); If BOOST_CHECK() is comment out, BOOST_CHECK_EQUAL() gets a template barf with the general comment, " template argument deduction/substitution failed:". Here are some of the complaints: D:\Boost_1_60_0/boost/test/tools/detail/print_helper.hpp:50:14: note: cannot convert 't' (type 'const DiGSE::Operand_Class_Test_Suite::Operand_Default_Constructor_Test::test_method()::UsedFor') to type 'std::_Setw' ostr << t; ^ D:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/iomanip:208:5: note: candidate: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setprecision) operator<<(basic_ostream<_CharT, _Traits>& __os, _Setprecision __f) D:\Boost_1_60_0/boost/test/tools/detail/print_helper.hpp:50:14: note: cannot convert 't' (type 'const DiGSE::Operand_Class_Test_Suite::Operand_Default_Constructor_Test::test_method()::UsedFor') to type 'std::_Setprecision' ostr << t; ^ At this point, it seems to be complaining about every io manipulator in existence. D:\Boost_1_60_0/boost/test/tools/detail/print_helper.hpp:50:14: note: mismatched types 'const std::piecewise_linear_distribution<_RealType>' and 'const DiGSE::Operand_Class_Test_Suite::Operand_Default_Constructor_Test::test_method()::UsedFor' ostr << t; Then it gets to the point of, apparently, dragging out all of the error messages it doesn't get to use very often: mismatched types*'const std::chi_squared_distribution<_RealType>' *and 'const DiGSE::Operand_Class_Test_Suite::Operand_Default_Constructor_Test::test_method()::UsedFor' ostr << t; ^ For the time being, I can simply use the explicit == check, but it looks like there's a problem here. Merrill Cornish

Merrill Cornish <merrill.cornish <at> earthlink.net> writes:
The simple answer is this: scoped enums are not printable (unlike old enums). Error message is a bit messy, but the good news is that I've checked in the change few days ago which will make it much more clear. Gennadiy

On 2/4/2016 9:03 PM, Gennadiy Rozental wrote:
scoped enums are not printable I've already run into that problem, so I wrote an inline function, enum2int(), to do a static_cast to int when I have to print one. But that aside, why does BOOST_CHECK(mUse == UsedFor::NOTIFY_INPUT); appear to work.
Some of your documentation implies that BOOST_CHECK_EQUAL(L, R) is equivalent to BOOST_CHECK(L == R), but it doesn't act that way, and Eclipse's expansion of BOOST_CHECK_EQUAL() shows a lot more than L++R. Merrill Cornish

Merrill Cornish <merrill.cornish <at> earthlink.net> writes:
On 2/4/2016 9:03 PM, Gennadiy Rozental wrote:
scoped enums are not printable I've already run into that problem, so I wrote an inline function, enum2int(), to do a static_cast to int when I have to print one.
Why not implement operator<<?
But that aside, why does BOOST_CHECK(mUse == UsedFor::NOTIFY_INPUT); appear to work.
As it should.
Some of your documentation implies that BOOST_CHECK_EQUAL(L, R) is equivalent to BOOST_CHECK(L == R),
In spirit. The difference is that BOOST_CHECK_EQUAL attempts to report mismatched values. In any case you should start using BOOST_TEST(a==b) for all your assertions. Gennadiy
participants (2)
-
Gennadiy Rozental
-
Merrill Cornish