-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
"enum value does not fit" for uint64 enums #5161
Comments
At the same time we should also allow empty enums. |
This issue has a simple solution, but there is a hidden problem.
|
Hah, that's unfortunate.. looks like we need a special case there? |
I think we can split the current struct EnumValBase {
std::string name;
std::vector<std::string> doc_comment;
Type union_type;
};
template <typename T>
struct EnumVal {
EnumValBase base;
T value;
}; Not sure on the reflection side. I feel we can use union-like type there. |
I'm not sure how that helps, since the type of the enum is only known at runtime (in the parser). I think the changes can be entirely in code. We can obtain the desired data with |
In this way, every code that needs to access |
@iceb0y I don't think this can work.. Now |
@iceb0y do you already have a solution? I think it is acceptable to use simple Implicit signed to unsigned cast is modulo 2n cast by the C++ standard. |
Looking at code I agree that it's better to dispatch at value level than higher level. We can continue to use |
@aardappel |
Thanks @vglavnyy ! |
@aardappel what do you think about In C++ it is possible to set "sign" bit using static_cast from an unsigned value or using an explicit negative value. For other languages, explicit negation may be the only solution. In C++ there are no enum test_i8 : int8_t {
b0 = 1 << 0,
b7_err = 1<< 7, // this left-shift is UB
b7_ok = -128 // well-defined
} C# has [Flags] attribute, but also doesn't allow [Flags]
enum test_i8 : sbyte
{
b0 = 1 << 0,
b7_err = 1 << 7, // compile time error, 128 is out of range
b7_ok = -128 // valid
} Can we limit the signed |
Any enum values can be combined by OR: Lines 1391 to 1407 in f93d0f6
What does "represent the flags" mean in the grammar? |
I am hoping programmers can make informed choices about what integer type works for them.. if you really are actually using all 32-bits I hope you're smart enough to choose unsigned :) "representing flags" means "are intended as flags, either because they use |
- fix enum with uint64 - hide the implementation of enums from code generators
I have implemented it without restrictions.
Perhaps it is better to add the character |
You should also be able to put I agree the syntax is strange, and an explicit |
Close? |
Thanks! |
Example:
Result:
Looks like this overflowed:
flatbuffers/src/idl_parser.cpp
Line 1677 in 7d3930a
Introduced in 5c0f914.
The text was updated successfully, but these errors were encountered: