-
Notifications
You must be signed in to change notification settings - Fork 6
Description
I realize you may not be maintaining this library currently, but I may have found a bug, and I'd be remiss in not sharing the information.
It seems the Meta Enum member values may not be correct if an enumerant is initialized using the value of a previous enumerant. Here's a self-contained example:
#include <iostream>
#include "meta_enum.hpp"
meta_enum_class(Enum, int, a, b, c = b, d);
std::ostream & operator<<(std::ostream & stream, Enum const value) {
return stream << static_cast<int>(value);
}
int main(int const argc, char * const argv[]) {
std::cout << "Expected values : ";
std::cout << Enum::a << Enum::b << Enum::c << Enum::d << std::endl;
std::cout << "Meta Enum values: ";
for (auto const & member : Enum_meta.members) {
std::cout << member.value;
}
std::cout << std::endl;
}Output:
Expected values : 0112
Meta Enum values: 0123
I think the issue is in the 'Type##_internal_size' function. With this approach, the int wrapper for 'b' is empty, and when the int wrapper for 'c' is created, it's empty too. So the method being used there doesn't seem to be able to account for assignment from previous enumerants (unless I'm mistaken).
I stumbled across this while trying some different enum libraries and doing some experimenting of my own. If I manage to solve this particular problem in my own code, I'll try to post back.