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

Fix magic_enum::containers::set erase function for Clang compilers #308

Merged
merged 1 commit into from
Nov 12, 2023

Conversation

Ry-DS
Copy link
Contributor

@Ry-DS Ry-DS commented Nov 12, 2023

The erase function does not compile on the following:

clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix

When building for C++ 17 and 20 (note these specific configurations are all I tested).

Compile error:

include/magic_enum_containers.hpp:985:10: error: no viable conversion from 'typename container_type::reference' (aka 'reference_impl<>') to 'bool'
    bool res = ref;
         ^     ~~~
(retracted): note: in instantiation of member function 'magic_enum::containers::set<Retracted>::erase' requested here
        set.erase(Retracted::ELEMENT);
                         ^
include/magic_enum_containers.hpp:526:38: note: explicit conversion function is not a candidate
    [[nodiscard]] constexpr explicit operator bool() const noexcept { return (parent->a[num_index] & bit_index) > 0; }

This PR fixes that, while adding tests for this function to ensure this template is instansiated and exercised.

@Ry-DS Ry-DS changed the title Fix magic_enum::containers::set erase function Fix magic_enum::containers::set erase function for Clang compilers Nov 12, 2023
@Neargye
Copy link
Owner

Neargye commented Nov 12, 2023

Thanks!

@Neargye Neargye merged commit cd5fd2c into Neargye:master Nov 12, 2023
18 checks passed
@Neargye Neargye added this to the v0.9.4 milestone Nov 12, 2023
@Ry-DS
Copy link
Contributor Author

Ry-DS commented Nov 13, 2023

In hindsight, removing the explicit keyword here:

[[nodiscard]] constexpr explicit operator bool() const noexcept { return (parent->a[num_index] & bit_index) > 0; }

might have made more sense. Regardless either solution works, thanks for the prompt merge + release! 🙌

@Ry-DS Ry-DS deleted the fix_erase_function_set branch November 13, 2023 07:30
@Neargye
Copy link
Owner

Neargye commented Nov 13, 2023

Yes, perhaps this fix makes sense, in the original bitset it is not marked explicit https://en.cppreference.com/w/cpp/utility/bitset/reference

If you have time, I will be glad to accept PR

Ry-DS added a commit to Ry-DS/magic_enum that referenced this pull request Nov 17, 2023
Ry-DS added a commit to Ry-DS/magic_enum that referenced this pull request Nov 17, 2023
@Ry-DS
Copy link
Contributor Author

Ry-DS commented Nov 17, 2023

was about to make one but I see it's handled in 677636e, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants