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 /tests/at_tests.cpp | |
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 'tests/at_tests.cpp')
-rw-r--r-- | tests/at_tests.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/at_tests.cpp b/tests/at_tests.cpp index 2f9e999..7f07be0 100644 --- a/tests/at_tests.cpp +++ b/tests/at_tests.cpp @@ -14,6 +14,12 @@ // /////////////////////////////////////////////////////////////////////////////// +#ifdef _MSC_VER +// blanket turn off warnings from CppCoreCheck from catch +// so people aren't annoyed by them when running the tool. +#pragma warning(disable : 26440 26426) // from catch +#endif + #include <catch/catch.hpp> // for AssertionHandler, StringRef, CHECK_THROW... #include <gsl/gsl_util> // for at @@ -23,12 +29,15 @@ #include <initializer_list> // for initializer_list #include <vector> // for vector + namespace gsl { struct fail_fast; } // namespace gsl using gsl::fail_fast; +GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute +GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute TEST_CASE("static_array") { int a[4] = {1, 2, 3, 4}; @@ -45,6 +54,8 @@ TEST_CASE("static_array") CHECK_THROWS_AS(gsl::at(c_a, 4), fail_fast); } +GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute +GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute TEST_CASE("std_array") { std::array<int, 4> a = {1, 2, 3, 4}; @@ -61,6 +72,8 @@ TEST_CASE("std_array") CHECK_THROWS_AS(gsl::at(c_a, 4), fail_fast); } +GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute +GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute TEST_CASE("StdVector") { std::vector<int> a = {1, 2, 3, 4}; @@ -77,9 +90,11 @@ TEST_CASE("StdVector") CHECK_THROWS_AS(gsl::at(c_a, 4), fail_fast); } +GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute +GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute TEST_CASE("InitializerList") { - std::initializer_list<int> a = {1, 2, 3, 4}; + const std::initializer_list<int> a = {1, 2, 3, 4}; for (int i = 0; i < 4; ++i) { CHECK(gsl::at(a, i) == i + 1); @@ -93,6 +108,9 @@ TEST_CASE("InitializerList") } #if !defined(_MSC_VER) || defined(__clang__) || _MSC_VER >= 1910 +GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute +GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute +GSL_SUPPRESS(con.4) // NO-FORMAT: attribute static constexpr bool test_constexpr() { int a1[4] = {1, 2, 3, 4}; @@ -114,3 +132,4 @@ static constexpr bool test_constexpr() static_assert(test_constexpr(), "FAIL"); #endif + |