Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang Defect with enums inside a templated class #65

Closed
fatal-err opened this issue Nov 25, 2020 · 1 comment
Closed

Clang Defect with enums inside a templated class #65

fatal-err opened this issue Nov 25, 2020 · 1 comment
Labels
help wanted Extra attention is needed invalid This doesn't seem right

Comments

@fatal-err
Copy link

fatal-err commented Nov 25, 2020

There's a problem with (even the current trunk version) of clang with this code:

#include <https://raw.githubusercontent.com/Neargye/magic_enum/master/include/magic_enum.hpp>

template <typename T = int>
struct test {
    enum class Color { RED, BLUE, GREEN};
};

template <typename type>
static constexpr bool are_values_sequential = []() constexpr noexcept -> bool {
    const auto vals = magic_enum::enum_values<type>();
    for (std::size_t i = 0; i < vals.size(); ++i)
        if (magic_enum::enum_integer(vals[i]) != i)
            return false;
    return true;
}();

static_assert(are_values_sequential<test<int>::Color>);

https://godbolt.org/z/KWWE1f

https://raw.githubusercontent.com/Neargye/magic_enum/master/include/magic_enum.hpp:653:3: error: static_assert failed due to requirement 'detail::count_v<test<int>::Color, false> > 0' "magic_enum requires enum implementation and valid max and min."

The above code works in GCC though.

The problem seems to appear when the enum is inside a templated class.

@fatal-err fatal-err changed the title Clang Defect Clang Defect with enums inside a templated class Nov 25, 2020
@Neargye
Copy link
Owner

Neargye commented Nov 25, 2020

I do not yet know what is the reason for this behavior.

But workaround static_assert(are_values_sequential<decltype(test<int>::Color::RED)>); - work on clang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants