Neargye / magic_enum

Static reflection for enums (to string, from string, iteration) for modern C++, work with any enum type without any macro or boilerplate code
MIT License
4.88k stars 434 forks source link

Incorrect behaviour with clang on enums defined inside template classes #296

Closed johnilacqua closed 1 year ago

johnilacqua commented 1 year ago

When used on an enum defined inside a templated class, magic_enum::enum_count<MyEnum>() returns 0 instead of the correct value when compiled with clang.

https://godbolt.org/z/vqasE9M13

#include <magic_enum.hpp>

template <typename SomeType>
class TestClass
{
    enum class MyEnum
    {
        VALUE
    };

    static_assert(magic_enum::enum_count<MyEnum>() == 1);
};

TestClass<int> t;
johnilacqua commented 1 year ago

To add, this only happens with an enum class, not if it's just an enum.

Neargye commented 1 year ago

Hi, Unfortunately, this is a problem with the Сlang compiler, perhaps an optimization bug, we don’t know how to get around it See https://github.com/Neargye/magic_enum/issues/164, https://github.com/Neargye/magic_enum/issues/65