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

static assertion failed with gcc 9.2.1 #28

Closed
morph208 opened this issue Feb 21, 2020 · 10 comments
Closed

static assertion failed with gcc 9.2.1 #28

morph208 opened this issue Feb 21, 2020 · 10 comments
Labels
help wanted Extra attention is needed invalid This doesn't seem right

Comments

@morph208
Copy link

Hello,

We have been trying to use magic_enum::enum_count. It works well with Visual Studio 2017 but does not compile with gcc 9.2.1. Here is the code:

enum class MyEnum : std::size_t
{
    Value0,
    Value1,
    Value2
};
constexpr std::size_t countEnum = magic_enum::enum_count<MyEnum>();

And with gcc 9.2.1 we have the following issue:

MagicEnum.h:442:26: error: static assertion failed: magic_enum::enum_range requires enum implementation and valid max and min.
static_assert( count > 0, "magic_enum::enum_range requires enum implementation and valid max and min." );

We have the latest version of MagicEnum as of today. We have looked at the limitations, we don't seem to be in one of those situations. Did we miss anything? It looks like it is supposed to work from gcc 9 and upward.

Thank you so much for your work and very nice contribution. Magic enum seems pretty cool.

Cheers,

Olivier

@Neargye
Copy link
Owner

Neargye commented Feb 21, 2020

Hi @morph208,

Example gcc9.2: https://godbolt.org/z/d3cXHr

This situation may occur if forward declared enum: https://godbolt.org/z/h9b_SK

@morph208
Copy link
Author

Thanks for your very quick reply. It's not forward declared but maybe I cannot use it like I do. I'm trying to get the size of the enum to declare an std::array of that size. Since the count it's constexpr I would have expected to work. I do not call it from the main like you did in your example, I should probably have told you that earlier. Sorry about that. Anyway it compiles and works as expected with VS2017. Here the complete code below:

#pragma once
#include "MagicEnum.h"
#include <array>

namespace myNamespace
{
enum class MyEnum  : std::size_t
{
    Value0,
    Value1,
    Value2,
};
constexpr std::size_t countEnum = magic_enum::enum_count<MyEnum>();

using MyList = std::array<bool, countEnum>;

class MyClass
{
public:
    MyClass() = default;
    ~MyClass() = default;

private:
    MyList m_myList;
};
}    // end of namespace myNamespace

@Neargye
Copy link
Owner

Neargye commented Feb 21, 2020

Thanks for update example, I will check it later.

@Neargye
Copy link
Owner

Neargye commented Feb 25, 2020

Hi @morph208,
Could you help to debug and run some code

std::cout << (int)MyEnum::Value0 << magic_enum::enum_name<MyEnum::Value0>() << std::endl;
std::cout << (int)MyEnum::Value1 << magic_enum::enum_name<MyEnum::Value1>() << std::endl;
std::cout << (int)MyEnum::Value2 << magic_enum::enum_name<MyEnum::Value2>() << std::endl;

@Neargye Neargye added the help wanted Extra attention is needed label Mar 1, 2020
@Neargye Neargye self-assigned this Mar 1, 2020
@morph208
Copy link
Author

morph208 commented Mar 6, 2020

Hey @Neargye

Sorry for the delay. I was very busy with a release. Anyway, here the output you needed:

0Value0
1Value1
2Value2

Obviously the output was generated on Windows with VS 2017. I cannot give you an output on gcc 9.2.1 since it does not even compile.

@morph208
Copy link
Author

Any news on this? I haven’t heard from you since early March.

@Neargye Neargye added the invalid This doesn't seem right label May 5, 2020
@Neargye
Copy link
Owner

Neargye commented May 5, 2020

Hi @morph208,
Sorry for the long answer, to be honest, I had a very busy time.
I don’t know yet where the is a problem. Could you tell the OS and the version of the compiler on which the bug is occur, I will try to play it in the virtual machine.

@morph208
Copy link
Author

morph208 commented May 5, 2020

No worries, totally understandable. The OS is Linux Mint 19 and the compiler is gcc 9.2.1.

@zweistein22
Copy link

Hello,
I have the same compile error
"magic_enum::enum_range requires enum implementation or valid max and min."
, but in a special snapcraft.yaml build.
Same source code as on linux ubuntu 18 same compiler gcc 9.3, everything same, but since yesterday inside snapcraft.yaml compilation broken . I played around with LC_LOCAL and libgtk2.0-dev, but cannot reproduce yet... compilation always broken which makes me think of a recent gcc or magic-enum change.

@egorpugin
Copy link

#53 looks similar to this one.

@Neargye Neargye removed their assignment Jan 8, 2021
@Neargye Neargye closed this as completed Jun 1, 2021
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

4 participants