Standard Library Modules: Fix warning C4365 (signed/unsigned mismatch) with /ZI
#4487
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes DevCom-10610863 "Importing module std warns on signed/unsigned mismatch" (internal VSO-1992367 / AB#1992367 ).
Problem
The problem was that the
/ZI
compiler option (debug info for Edit and Continue) messes with__LINE__
, making it a variable of typelong
instead of an integer literal. This variable can emit sign conversion warnings when passed to functions taking unsigned types (whereas integer literals don't, regardless of their type, because the compiler can directly see that the value is unaffected).Fix
The fix is to
static_cast<unsigned int>
, matching what_invalid_parameter()
takes.I'm also slightly updating the previous comment, since
// sentence fragment
is fine by itself, but multiple sentences need punctuation for clarity.Extra fix/cleanup
There was one more potential occurrence of signed/unsigned mismatch warnings involving
__LINE__
, when we call_invoke_watson()
for_HAS_EXCEPTIONS=0
. I couldn't actually repro a warning here, but we can eliminate any risk - it turns out that_invoke_watson()
always ignores its parameters. SeeC:\Program Files (x86)\Windows Kits\10\Source\10.0.22621.0\ucrt\misc\invalid_parameter.cpp
.Unchanged
__LINE__
sThe rest of our
__LINE__
usage is with_malloc_dbg
and_calloc_dbg
:STL/stl/inc/xlocale
Line 43 in 191d51b
They take
int linenumber
, so along
will be fine.No test coverage
I've been testing with
/w14365
since the very beginning:STL/tests/std/tests/P2465R3_standard_library_modules/env.lst
Line 6 in 191d51b
However, we missed this for two reasons: (1) no
/ZI
coverage, and (2) we use_STL_CALL_ABORT_INSTEAD_OF_INVALID_PARAMETER
in our tests, which inherently bypasses the affected code. So, adding/ZI
wouldn't actually accomplish anything useful.Since we're highly centralized (all of
_STL_ASSERT
,_STL_VERIFY
,_STL_REPORT_ERROR
, and_INVALID_MEMORY_ORDER
ultimately lead to_STL_CRT_SECURE_INVALID_PARAMETER
), I believe that manual testing of this fix is sufficient as we're unlikely to regress.