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

Remove unneeded static_cast of return values. #3093

Merged
merged 2 commits into from
Sep 13, 2022

Conversation

AreaZR
Copy link
Contributor

@AreaZR AreaZR commented Sep 8, 2022

It just makes more noise were it should not happen.

It just makes more noise were it should not happen.
@AreaZR AreaZR requested a review from a team as a code owner September 8, 2022 15:39
@StephanTLavavej StephanTLavavej added the enhancement Something can be improved label Sep 9, 2022
@StephanTLavavej
Copy link
Member

Thanks, I agree that this is an improvement! The original intention was presumably to silence compiler warnings about truncation when building the STL, but either this was for another compiler (our sources were originally derived from a codebase that targeted many compilers beyond what we currently support), or the compiler has gotten smarter about emitting warnings in this scenario. (The issue is that return condition ? 1 : 2; is returning an int that isn't exactly a constant expression, even though both sides are constants, so some compilers might warn about truncating int to short.)

As long as the STL builds warning-free, I believe this change is fine to make. We also already have return statements that don't cast:

STL/stl/src/xdint.cpp

Lines 10 to 16 in f9697fc

short _Dint(double* px, short xexp) { // test and drop (scaled) fraction bits
const auto ps = reinterpret_cast<_Dval*>(px);
short xchar = (ps->_Sh[_D0] & _DMASK) >> _DOFF;
if (xchar == _DMAX) {
return (ps->_Sh[_D0] & _DFRAC) == 0 && ps->_Sh[_D1] == 0 && ps->_Sh[_D2] == 0 && ps->_Sh[_D3] == 0 ? _INFCODE
: _NANCODE;

I see a few more sites that can be changed, so I'll validate and push a commit.

@StephanTLavavej StephanTLavavej self-assigned this Sep 12, 2022
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit cff24b3 into microsoft:main Sep 13, 2022
@StephanTLavavej
Copy link
Member

Thanks for this code cleanup! 😸 😸 😸 😸 😸 😸 😸 😸 😸

@AreaZR AreaZR deleted the locks branch September 26, 2022 16:06
CaseyCarter pushed a commit to CaseyCarter/STL that referenced this pull request Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants