Skip to content

Remove unneeded static_cast of return values.#3093

Merged
StephanTLavavej merged 2 commits into
microsoft:mainfrom
mike-goutokuji:locks
Sep 13, 2022
Merged

Remove unneeded static_cast of return values.#3093
StephanTLavavej merged 2 commits into
microsoft:mainfrom
mike-goutokuji:locks

Conversation

@mike-goutokuji
Copy link
Copy Markdown
Contributor

It just makes more noise were it should not happen.

It just makes more noise were it should not happen.
@mike-goutokuji mike-goutokuji 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@mike-goutokuji mike-goutokuji 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