-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Improve warning suppressions for header units #3069
Merged
StephanTLavavej
merged 9 commits into
microsoft:main
from
StephanTLavavej:warning-suppression
Sep 3, 2022
Merged
Improve warning suppressions for header units #3069
StephanTLavavej
merged 9 commits into
microsoft:main
from
StephanTLavavej:warning-suppression
Sep 3, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Example: D:\GitHub\STL\out\build\x64>type woof.cpp template <typename T> int func() { constexpr auto N = sizeof(T); #ifdef USE_IF_CONSTEXPR if constexpr (N < 4) { #else if (N < 4) { #endif return 11; } else { return 22; } } int main() { (void) func<short>(); (void) func<double>(); } D:\GitHub\STL\out\build\x64>cl /EHsc /nologo /W4 /analyze /std:c++latest /MTd /Od woof.cpp woof.cpp woof.cpp(7): warning C4127: conditional expression is constant woof.cpp(2): note: consider using 'if constexpr' statement instead woof.cpp(16): note: see reference to function template instantiation 'int func<short>(void)' being compiled D:\GitHub\STL\out\build\x64\woof.cpp(7) : warning C6326: Potential comparison of a constant with another constant. D:\GitHub\STL\out\build\x64\woof.cpp(7) : warning C6326: Potential comparison of a constant with another constant. D:\GitHub\STL\out\build\x64>cl /EHsc /nologo /W4 /analyze /std:c++latest /MTd /Od /DUSE_IF_CONSTEXPR woof.cpp woof.cpp D:\GitHub\STL\out\build\x64> Verified: D:\GitHub\STL\out\build\x64>type meow.cpp #include <algorithm> #include <iostream> #include <vector> using namespace std; void print(const vector<int>& v) { for (const auto& e : v) { cout << e << ", "; } cout << "\n"; } int main() { vector<int> result{-1, -1, -1, -1}; vector<int> v{11, 22, 33, 44}; print(v); reverse(v.begin(), v.end()); print(v); ranges::reverse(v); print(v); print(result); reverse_copy(v.begin(), v.end(), result.begin()); print(result); ranges::fill(result, -1); print(result); ranges::reverse_copy(v, result.begin()); print(result); } D:\GitHub\STL\out\build\x64>cl /EHsc /nologo /W4 /analyze /std:c++latest /MTd /Od /I D:\GitHub\STL\stl\inc meow.cpp && meow meow.cpp 11, 22, 33, 44, 44, 33, 22, 11, 11, 22, 33, 44, -1, -1, -1, -1, 44, 33, 22, 11, -1, -1, -1, -1, 44, 33, 22, 11,
…rg_store::_Store_impl.
StephanTLavavej
added
bug
Something isn't working
modules
C++23 modules, C++20 header units
labels
Sep 2, 2022
CaseyCarter
approved these changes
Sep 2, 2022
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 is a perma-workaround for DevCom-10097021 / VSO-1581774 "C++ STL header
<format>
causes C4296 warning that need to be suppressed every time". @cdacamar is investigating the underlying compiler bug, where#pragma
s within functions aren't properly stored within an IFC. In the meantime, if we consistently push/disable/pop around a function, we'll avoid this problem.Most of our push/disable/pops are already outside functions, so only a couple of occurrences need to be changed:
<format>
: Move push/disable/pop outside of_Write_integral
.<thread>
: Move push/disable/pop outside_Start
.And one more occurrence can avoid pragmas entirely (I verified that this continues to suppress the warning):
<regex>
: Use_Analysis_assume_
instead of push/disable/pop.Next, this isn't being directly motivated by user bug reports, but I'm nervous about the occasional use of
#pragma warning(suppress : NUM)
in the headers. This seems likely to have similar problems with header units, and @AnjuDel recently encountered apparently squirrelly behavior ofsuppress
in ATL/MFC. I think we should consistently push/disable/pop outside functions, which is a simple convention (and not too verbose):<ranges>
: Replace 2x suppress with push/disable/pop outside ofiota_view::size
.<span>
: Replace suppress with push/disable/pop outsidesize_bytes
,front
,back
.<xstring>
: Replace suppress with push/disable/pop outside ofresize_and_overwrite
.<atomic>
: Replace suppress with push/disable/pop outside of_Atomic_thread_fence
.<format>
: Replace suppress with push/disable/pop outside of_Format_arg_store::_Store_impl
.Finally, one kind of suppression can be eliminated entirely, due to recent
/analyze
improvements:if constexpr
.Click to expand example:
Verified this change: