[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
Merrill Cornish
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
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
On 2/4/2016 9:03 PM, Gennadiy Rozental wrote: 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
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