-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Use static_cast rather than reinterpret_cast whenever possible #14597
Conversation
|
test/core/util/trickle_endpoint.cc
Outdated
@@ -132,7 +132,7 @@ static int te_get_fd(grpc_endpoint* ep) { | |||
} | |||
|
|||
static void te_finish_write(void* arg, grpc_error* error) { | |||
trickle_endpoint* te = static_cast<trickle_endpoint*>(arg); | |||
trickle_endpoint* te = reinterpret_cast<trickle_endpoint*>(arg); |
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.
If static_cast
was compiling here, why switch to reinterpret_cast
?
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.
Oops, I slipped. Thanks for noticing.
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.
Specifically, my method here was to s/reinterpret_cast/static_cast/g
, get all the build errors and change those back with an Emacs macro. Looks like I slipped here. I'll check the others.
|
|
1 similar comment
|
|
1 similar comment
|
Thanks for doing this Vijay! From the errors, it looks like some of the conversions weren't part of a hierarchy or void * to and fro conversions. LGTM once it builds :) |
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.
LGTM once it builds
I wasn't building Cronet until now. Hopefully this goes through now. |
|
|
|
|
|
1 similar comment
|
Rebased, diff unchanged |
|
|
|
In particular, you should use
static_cast
for going up or down a class hierarchy or for converting betweenT*
andvoid*
.Many of the remaining uses of
reinterpret_cast
are for things that are "morally" part of a class hierarchy (e.g.,grpc_endpoint
vsmock_endpoint
) but currently aren't because they are expressed in C-style. This will allow further reduction ofreinterpret_cast
in the future.