Repository navigation
Dev/annagrin/fix cppcorecheck warnings - #703
Neil MacIntosh (neilmacintosh) merged 19 commits into
Conversation
b444c68 to
0b94bc3
Compare
- Added CMakeSettings.json for VS Open Folder configuration
- So we can easily run CppCoreCheck in VS
- Fixed CppCorecheck warnings where it made sense
- Suppressed the rest
- Some suppression does not work due to compiler/tool bugs,
so replaced by #pragma disable
- CppCoreCheck has noise, suppressed those with comments
- Catch produces many warnings, blanket-supressed them all
- Had to fix clang formatting to keep attributes in place
- clang-format does not support attributes, so I am using
- "CommentPragmas: '^ NO-FORMAT:'" to skip formatiting on them
- Removed GSL_NOEXCEPT macro, removed incorred noexcepts
34491bd to
439068b
Compare
|
It looks like you addressed much more warnings than I do in PR #642 and in a slightly different way (suppress before the line with the warning, not at function level). But I am surprised you did not #ifdef to check for different compiler support for gsl::support (MSVC vs. clang vs. gcc). How do we want to proceed? Do you extend your PR and I close mine? Or shall we keep both open? With my code in PR #642 and your changes I still get this warning:
If you add a |
|
Werner Henze (@beinhaerter) I was experimenting:) I am happy to merge your changes into mine, but I would like to avoid ifdefs - currently I am trying my luck with forcing the compilers to ignore unknown attributes. |
Thanks, I missed that. I will use narrow_cast to fix the warning instead of suppressing in this case. |
clang5.0 and up does not allow attributes on return statemets in constexpr functions
|
Werner Henze (@beinhaerter) Would you be able to review the PR? I merged in your changes, but replaced them with my macro. Previously we were talking about ifdefing out attributes for gcc and clang. This time I wanted an experiment - how close can I get to actually keeping them all for all compilers, given that
I achieved partial success:
Thanks in advance! This change addresses #688, #432, #451, #578, #220 and probably more. |
| #define GSL_SUPPRESS(x) [[gsl::suppress(x)]] | ||
| #else | ||
| #if defined(__clang__) | ||
| #define GSL_SUPPRESS(x) [[gsl::suppress("x")]] |
There was a problem hiding this comment.
Has someone opened a bug report against Clang to get this syntax variation fixed?
There was a problem hiding this comment.
I will (sent request to join their bug database)
| #else | ||
| [[gsl::suppress(f.6)]] | ||
| #endif | ||
| GSL_SUPPRESS(f.6) // NO-FORMAT: attribute |
There was a problem hiding this comment.
Couldn't we use a conditional noexcept for these cases, based on the throw/terminate build-mode? Yes, it might involve a macro, but probably less directly and would be no worse than suppressions. But I may be missing something else here.
There was a problem hiding this comment.
It does work, adding
|
|
||
| // don't warn about function style casts in byte related operators | ||
| #pragma warning(disable : 26493) | ||
| // Turn off rules that generate too much noise. To be fixed in the static analysis tool. |
There was a problem hiding this comment.
If that is MSVC /analyze, perhaps we should just call it that?
| return static_cast<byte>(t); | ||
| } | ||
| template <> | ||
| // GSL_SUPPRESS(type.4) // NO-FORMAT: attribute // TODO: suppression does not work |
There was a problem hiding this comment.
I can't remember, but is there a reason this can't be just return {t};? If there is, perhaps we should leave behind a comment to explain to others reading the code.
There was a problem hiding this comment.
The only reason is that it does not work with c++14... will add comment.
|
|
||
| // | ||
| // make suppress attributes parse for some compilers | ||
| // Hopefully temporary until suppresion stardization occurs |
There was a problem hiding this comment.
Typos: "suppression standardization"
| // don't warn about function style casts in byte related operators | ||
| #pragma warning(disable : 26493) | ||
| // Turn off rules that generate too much noise. To be fixed in the static analysis tool. | ||
| #pragma warning(disable : 26493) // don't use c-style casts |
There was a problem hiding this comment.
Could this be suppressed with GSL_SUPPRESS(type.4) or as we know this is MSVC maybe with [[gsl::suppress(x)]]?
There was a problem hiding this comment.
Had to use #pragma suppress because MSVC has a bug where suppression does not always work in templates. To be fixed...
There was a problem hiding this comment.
Added comment to clarify
| #pragma warning(disable : 4127) // conditional expression is constant | ||
| #pragma warning(disable : 4702) // unreachable code | ||
|
|
||
| // Turn off rules that generate too much noise. To be fixed in the static analysis tool. |
There was a problem hiding this comment.
If you have some MS internal insights and expect these fixes to be in version x of MSVC then maybe we could only use them #if _MSC_VER < x.
There was a problem hiding this comment.
Not yet, will do when we have the fixes planned.
| } | ||
|
|
||
| constexpr bool operator==(const multi_span_index& rhs) const GSL_NOEXCEPT | ||
| GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute |
There was a problem hiding this comment.
Here and in the next line we could remove the space in "bounds ." and align it with the format in the other suppresses.
There was a problem hiding this comment.
There seems to be an issue with clang-format where it inserts the space even when it is supposed to ignore the commented line. Will fix.
| } | ||
|
|
||
| size_type elementNum(std::size_t dim) const GSL_NOEXCEPT | ||
| GSL_SUPPRESS(c.128) // NO-FORMAT: attribute // no pointers to BoundsRanges should be ever used |
There was a problem hiding this comment.
If this is required would it make sense to add a private operator& to prevent someone taking a pointer to the object?
There was a problem hiding this comment.
Makes sense, will add as a separate PR later, thanks!
| for (std::size_t i = 0; i < rank; ++i) { | ||
| ret += (m_extents[i] - 1) * m_strides[i]; | ||
| } | ||
| for (std::size_t i = 0; i < rank; ++i) { ret += (m_extents[i] - 1) * m_strides[i]; } |
There was a problem hiding this comment.
In my opinion the old loop code block was better readable than this one liner. This also applies to changes below (where I don't mention it again).
There was a problem hiding this comment.
Those are clang-format changes... Normally I would not introduce formatting changes at the same time as code changes, but had to do so in this case (clang-format does not support attributes)
| typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>, | ||
| std::remove_cv_t<OtherValueType>>::value>> | ||
| constexpr bool operator==(const multi_span<OtherValueType, OtherDimensions...>& other) const | ||
| noexcept |
There was a problem hiding this comment.
Previously the GSL_NOEXCEPT was on the same line. If there is no reason to put it on a new line, I would leave it there. Or is this something the editor automatically does? The same applies below.
There was a problem hiding this comment.
yeah, this is clang-format
| { | ||
|
|
||
| GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute | ||
| void validateThis() const { |
There was a problem hiding this comment.
"{" in the next line would be more consistent with the rest of the code.
There was a problem hiding this comment.
will try to keep revert it, will see if clang-format will change it again
|
|
||
| public: | ||
| reference operator*() const GSL_NOEXCEPT | ||
| reference operator*() const |
There was a problem hiding this comment.
Why is noexcept removed here? I know that validateThis is not noexcept, but noexcept is not removed for operator -> which looks quite similar.
There was a problem hiding this comment.
mistake in operator-> ... will fix
| constexpr span(std::array<ArrayElementType, N>& arr) noexcept | ||
| : storage_(&arr[0], details::extent_type<N>()) | ||
| { | ||
|
|
There was a problem hiding this comment.
In other places you are replacing "{\n}" by "{}", here and below you are adding a new line?
There was a problem hiding this comment.
thanks for catching!
| typename = std::enable_if_t<std::is_convertible< | ||
| T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>> | ||
| bool operator<(gsl::basic_string_span<CharT, Extent> one, const T& other) GSL_NOEXCEPT | ||
| bool operator<(gsl::basic_string_span<CharT, Extent> one, const T& other) |
There was a problem hiding this comment.
I do not understand why the both operator< (and other operators below) differ in noexcept, but I assume you checked that and there is a reason behind it.
There was a problem hiding this comment.
thy shouldn't, thanks!
| -Werror | ||
| -Wextra | ||
| -Wno-missing-braces | ||
| -Wno-unknown-attributes |
There was a problem hiding this comment.
I bet you have tested it, but I cannot find any information online describing what -Wunknown-attributes or -Wno-unknown-attributes do. And confusingly enough I find code that uses -Wunknown-attribute (no 's'). Do you have a link to a page describing it (gcc?, clang?)?
There was a problem hiding this comment.
I couldn't find any documentation but clang gives the following warning on unknown attributes:
warning: unknown attribute ... ignored [-Wunknown-attributes]
So I took a guess at removing that:)
There was a problem hiding this comment.
Can't reply to your comment below - sounds reasonable, created PR #719
|
I like getting rid of I wonder if we can keep a single, central definition for I would have split this into one PR for the |
|
Thanks Anna Gringauze (@annagrin), that's a huge diff! Looks good to me. |
Fixed CppCoreCheck warnings in GSL and tests
Added CMakeSettings.json for VS Open Folder configuration
Fixed CppCorecheck warnings where it made sense
Suppressed the rest
Had to fix clang formatting to keep attributes in place
"CommentPragmas: '^ NO-FORMAT:'" to skip formatiting on them