boostorg / mp11

C++11 metaprogramming library
http://boost.org/libs/mp11
242 stars 66 forks source link

mp_map_find seems not working properly using g++ #72

Open HanatoK opened 2 years ago

HanatoK commented 2 years ago

The code is at https://godbolt.org/z/KvjecnTe3. The code can be compiled if switching to clang 13.0.1, but gcc 11.2 or the trunk version fails. Interestingly, if I comment out line 22 and 23 as

 // boost::mp11::mp_list<enum_<Foo::A1>, int>,
 // boost::mp11::mp_list<enum_<Foo::A2>, double>,

then gcc can successfully compile the code. Any ideas?

pdimov commented 2 years ago

Looks like a GCC bug. I'll try to figure out why it happens. Here's a workaround:

template <auto EnumVal> using enum_ = std::integral_constant<decltype(EnumVal), EnumVal>;
pdimov commented 2 years ago

Interestingly, if I comment out line 22 and 23 as

Commenting out line 22 (Foo::A1) is enough. It looks like GCC doesn't take into account the type of EnumVal, just its value (which is 0 for both A1 and B1).

HanatoK commented 2 years ago

Thanks! this works for me. Just for your information, I tried similar code by using boost::mpl and it works (https://godbolt.org/z/zeGdoa3Te) for both gcc and clang.

Looks like a GCC bug. I'll try to figure out why it happens. Here's a workaround:

template <auto EnumVal> using enum_ = std::integral_constant<decltype(EnumVal), EnumVal>;
pdimov commented 2 years ago

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104867