-
Notifications
You must be signed in to change notification settings - Fork 34
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
capi: Add static assertions for FizzyValueType* vs. fizzy:ValType::* #821
Conversation
Codecov Report
@@ Coverage Diff @@
## master #821 +/- ##
=======================================
Coverage 99.28% 99.28%
=======================================
Files 86 86
Lines 13221 13221
=======================================
Hits 13126 13126
Misses 95 95
Flags with carried forward coverage won't be shown. Click here to find out more. |
{ | ||
A = 0xff | ||
}; | ||
EXPECT_EQ(to_underlying(A::A), 0xff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add `static_assert(std::is_same_v<decltype(to_underlying(A::A)), int>);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specs said it is at least int
. So this may fail on some platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also did you know that the C enum (decltype(C::A)
) defaults to unsigned int
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be bigger than int
only if some values don't fit int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For scoped enumerations (enum class
) the implicit underlying type is int
. In case value do not fit, this is compile error. https://godbolt.org/z/1x8ffaadW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we are adding C++ compiler compliance tests at this point 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted to know if this returns the same type as in the enum declaration. If you want to be explicit, you can define it as enum class A : int
.
{ | ||
A = 0xff | ||
}; | ||
static_assert(std::is_same_v<decltype(to_underlying(C::A)), unsigned int>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this stable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. This can be any integer type.
625c375
to
a229fe1
Compare
static_assert(FizzyValueTypeF64 == fizzy::to_underlying(fizzy::ValType::f64)); | ||
static_assert(FizzyValueTypeVoid == 0); | ||
static_assert(std::is_same_v<decltype(fizzy::to_underlying(fizzy::ValType::i32)), | ||
std::remove_const<decltype(FizzyValueTypeI32)>::type>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this overkill?
{ | ||
A = 0xff | ||
}; | ||
static_assert(std::is_same_v<decltype(to_underlying(C::A)), unsigned int>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. This can be any integer type.
{ | ||
A = 0xff | ||
}; | ||
EXPECT_EQ(to_underlying(A::A), 0xff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted to know if this returns the same type as in the enum declaration. If you want to be explicit, you can define it as enum class A : int
.
The others are explicit, intentionally left in the implicit one. |
No description provided.