Repository navigation
Suppress warnings on VS - #642
Conversation
|
|
||
| #if defined(_MSC_VER) | ||
| #pragma warning(push) | ||
| #pragma warning(disable : 26472) // Don't use a static_cast for arithmetic conversions. Use brace initialization, gsl::narrow_cast or gsl::narow (type.1: http://go.microsoft.com/fwlink/p/?LinkID=620417). |
9fdec73 to
794c97b
Compare
|
The message as written is exactly what the compiler outputs and what is documented at https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/code-quality/C26472.md. But if you want me to lie about the message text in the code comment, no problem. |
|
Thank you for your feedback, the documentation has been updated. |
794c97b to
309f507
Compare
309f507 to
fd91851
Compare
|
(As mentioned in #688.) I do prefer the use of I found a discussion on the use of these attributes in the GSL: isocpp/CppCoreGuidelines#1173 You still need an preprocessor
|
|
Neil MacIntosh (@neilmacintosh) Anna Gringauze (@annagrin) What do you think? How should it be handled? I'd be happy to get rid of the MSVC warnings and change my PR to a version that you prefer. |
|
Werner Henze (@beinhaerter) There are inconsistencies between compilers about suppression mechanisms, but I think it is fine to introduce conditional compilation around those (if only to show the need for standardization). |
|
Werner Henze (@beinhaerter) , Farwaykorse, I would welcome a PR! |
ae53651 to
f744f5a
Compare
|
I updated the PR to use [[gsl::suppress]]. In my opinion default behavior should be to suppress the warnings, so I am checking for the compilers that can't correctly suppress. I could not get the CI builds working with clang or g++ (tried |
- gsl::narrow, gsl::narrow_cast and gsl::at are the safe variants suggested by CppCoreGuideline. It does not make sense to let VS warn inside the implementation of these functions that unsafe static_cast is used and that the safe variants shall be used. - Suppress warning that throw_exception can be declared noexcept (for the GSL_TERMINATE_ON_CONTRACT_VIOLATION case)
f744f5a to
cffdde7
Compare
|
I am joining multiple suppresses into one gsl::suppress. If you want each gsl::suppress on a single line, please say so. |
|
Werner Henze (@beinhaerter) rerunning one of the failed tasks (machine problems it seems). I am planning to merge yours and then mine, if I figure out how to make my PR work for all compilers. |
For this short code snippet
VS 15.6.2 code analysis generates annoying warnings.
gsl::narrow, gsl::narrow_cast and gsl::at are the safe variants suggested by CppCoreGuideline. It does not make sense to let VS warn inside the implementation of these functions that unsafe static_cast is used and that the safe variants shall be used.