-
Notifications
You must be signed in to change notification settings - Fork 339
Conversation
src/aliased_buffer.h
Outdated
@@ -129,7 +129,7 @@ class AliasedBuffer { | |||
|
|||
template <typename T> | |||
inline Reference& operator=(const T& val) { | |||
aliased_buffer_->SetValue(index_, val); | |||
aliased_buffer_->SetValue(index_, static_cast<NativeT>(val)); |
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 agree that this does the same as the original code, but I'd prefer a solution where these operators aren't templates and the caller has to think about whether casting is valid. Otherwise we hide all of the danger inside this function instead of getting useful compiler warnings elsewhere.
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.
you'd still get compiler warnings w/ static_cast right? I don't remember why these functions were templated instead of taking a NativeT
as a param.
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, the explicit cast tells the compiler that you've carefully thought about what happens here and are okay with a possibly lossy conversion.
In reply to: 177183603 [](ancestors = 177183603)
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 see. So, it would be interesting to see if we could remove the templated functions here & push casts onto the caller. I don't recall why I did it this way previously.
src/aliased_buffer.h
Outdated
@@ -144,7 +144,7 @@ class AliasedBuffer { | |||
|
|||
template <typename T> | |||
inline Reference& operator+=(const T& val) { | |||
const T current = aliased_buffer_->GetValue(index_); | |||
const NativeT current = aliased_buffer_->GetValue(index_); |
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 don't think this is exactly equivalent to the existing code; it's actually a little better. If NativeT is wider than T, then it used to cast the existing value to T, perform the addition in T-space, and then cast back to NativeT. Now it should perform the addition as whichever is wider of T and NativeT since you're adding one of each, which could plausibly extend beyond the bounds of T.
lgtm |
src/aliased_buffer.h
Outdated
inline Reference& operator=(const T& val) { | ||
aliased_buffer_->SetValue(index_, val); | ||
inline Reference& operator=(const NativeT& val) { | ||
aliased_buffer_->SetValue(index_, static_cast<NativeT>(val)); |
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.
static_cast [](start = 40, length = 11)
static_cast from NativeT to NativeT is no longer needed
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.
Looks like there's a CI failure on macOS:
I'll have to investigate that before taking this upstream. |
* Unary minus usages on unsigned type * Implicit casts to/from input parameters
Opened upstream PR: nodejs/node#19665 |
Landed upstream PR nodejs/node#19665 |
Just looking for feedback from this group first, then I'll open a PR upstream. I saw these warnings while working on another issue and I believe these fixes to be equivalent to the implicit conversions that were happening before.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes