Closed ddevienne closed 3 years ago
Can you please post the exact code?
I suspect adding a trailing comma to your own example would be enough, but here goes anyway. I tried a bunch of things before realizing the trailing-comma mistake I made, w/ or w/o namespaces, separate TUs for the def and describe or not (former is my use case), longer names, etc... Thus the weird code.
PS: it's not the same exact code I sent errors for, but fails the same way
PPS: the test builds and passes when removing the trailing comma after eCcdEfghIjklmop
on BOOST_DESCRIBE_ENUM
#include <boost/describe.hpp>
#include <boost/mp11.hpp>
#include <boost/test/unit_test.hpp>
namespace Foo {
enum Bar { eAbcdEfghIjklm, eBcdEfghIjklmo, eCcdEfghIjklmop, };
BOOST_DESCRIBE_ENUM(Bar, eAbcdEfghIjklm, eBcdEfghIjklmo, eCcdEfghIjklmop,)
}
namespace {
template<class E> char const * enum_to_string(E e) {
const char* r = "(unnamed)";
boost::mp11::mp_for_each<boost::describe::describe_enumerators<E>>(
[&](auto D) {
if (e == D.value) {
r = D.name;
}
}
);
return r;
}
BOOST_AUTO_TEST_SUITE(DescribeTests)
BOOST_AUTO_TEST_CASE(test_enum) {
using namespace Foo;
Bar bar = eCcdEfghIjklmop;
std::string bar_name = enum_to_string(bar);
BOOST_CHECK_EQUAL(bar_name, "eCcdEfghIjklmop");
}
BOOST_AUTO_TEST_SUITE_END()
}
Microsoft Visual Studio Professional 2019, Version 16.7.6 Visual C++ 2019 00435-30010-36205-AA935 In C++17 mode.
Oh, forgot to mention, I layered your Describe lib on top of Boost 1.74, which is my company's current version I can't upgrade. Doesn't seem to give any trouble. Please keep this in mind, we can't all upgrade to the latest and greatest, yet still want to use your great libraries Peter :)
A trailing comma should now work (although it does cause a preprocessor warning on MSVC.)
My enums are code-generated, and the last enumerator has a trailing comma, which is OK in C++11. But when I copy/pasted it to turn it into a
BOOST_DESCRIBE_ENUM
, this yielding weird errors like below. Removing the trailing comma fixed the problem, but I wasted quite a bit of time on this.Any way to fix this, so it works with trailing commas, as enums do? Or at least tweak the code to yield a better error message?