diff options
author | Anna Gringauze <annagrin@microsoft.com> | 2018-08-12 21:44:17 -0700 |
---|---|---|
committer | Neil MacIntosh <neilmac@fb.com> | 2018-08-12 21:44:17 -0700 |
commit | cea0d0ac2bd775f0fb4c7e357a089979370ae3cd (patch) | |
tree | faa0e678f606971b55ef795d507d613d40e93de2 /include/gsl/gsl_byte | |
parent | 6a75903c79ff7109c24d281372005b622a9d9177 (diff) | |
download | platform_external_Microsoft-GSL-cea0d0ac2bd775f0fb4c7e357a089979370ae3cd.tar.gz platform_external_Microsoft-GSL-cea0d0ac2bd775f0fb4c7e357a089979370ae3cd.tar.bz2 platform_external_Microsoft-GSL-cea0d0ac2bd775f0fb4c7e357a089979370ae3cd.zip |
fix cppcorecheck warnings (#703)
* Added c++17 test configurations for clang5.0 and clang6.0
* Fixed CppCoreCheck warnings in GSL and tests
- 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
* Ignore unknown attributes
* ignore unknown attributes in noexception mode tests
* fixed C26472 in at()
* created GSL_SUPPRESS macro to allow all compilers to parse suppression attributes
* try to fix gcc compilation problems with attributes
* ignore gsl::suppress for gcc
* move suppression to function level on return statements
clang5.0 and up does not allow attributes on return statemets in constexpr functions
* move suppression to function level on return statements
* use GSL_SUPPRESS in algorithm_tests
* Addressed PR comments
Diffstat (limited to 'include/gsl/gsl_byte')
-rw-r--r-- | include/gsl/gsl_byte | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/include/gsl/gsl_byte b/include/gsl/gsl_byte index 6b770fd..bc18886 100644 --- a/include/gsl/gsl_byte +++ b/include/gsl/gsl_byte @@ -17,14 +17,28 @@ #ifndef GSL_BYTE_H #define GSL_BYTE_H +// +// make suppress attributes work for some compilers +// Hopefully temporary until suppresion standardization occurs +// +#if defined(_MSC_VER) +#define GSL_SUPPRESS(x) [[gsl::suppress(x)]] +#else +#if defined(__clang__) +#define GSL_SUPPRESS(x) [[gsl::suppress("x")]] +#else +#define GSL_SUPPRESS(x) +#endif // __clang__ +#endif // _MSC_VER + #include <type_traits> #ifdef _MSC_VER #pragma warning(push) -// don't warn about function style casts in byte related operators -#pragma warning(disable : 26493) +// Turn MSVC /analyze rules that generate too much noise. TODO: fix in the tool. +#pragma warning(disable : 26493) // don't use c-style casts // TODO: MSVC suppression in templates does not always work #ifndef GSL_USE_STD_BYTE // this tests if we are under MSVC and the standard lib has std::byte and it is enabled @@ -57,12 +71,12 @@ #define GSL_USE_STD_BYTE 0 -#endif //defined(__cplusplus) && (__cplusplus >= 201703L) +#endif //defined(__cplusplus) && (__cplusplus >= 201703L) && // (defined(__cpp_lib_byte) && (__cpp_lib_byte >= 201603) || // defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION >= 5000)) #endif // GSL_USE_STD_BYTE -#endif // _MSC_VER +#endif // _MSC_VER // Use __may_alias__ attribute on gcc and clang #if defined __clang__ || (__GNUC__ > 5) @@ -75,7 +89,6 @@ namespace gsl { #if GSL_USE_STD_BYTE - using std::byte; using std::to_integer; @@ -160,6 +173,8 @@ constexpr byte to_byte_impl(T t) noexcept return static_cast<byte>(t); } template <> +// NOTE: need suppression since c++14 does not allow "return {t}" +// GSL_SUPPRESS(type.4) // NO-FORMAT: attribute // TODO: suppression does not work constexpr byte to_byte_impl<true, unsigned char>(unsigned char t) noexcept { return byte(t); |