aboutsummaryrefslogtreecommitdiffstats
path: root/tests/algorithm_tests.cpp
diff options
context:
space:
mode:
authorAnna Gringauze <annagrin@microsoft.com>2018-08-12 21:44:17 -0700
committerNeil MacIntosh <neilmac@fb.com>2018-08-12 21:44:17 -0700
commitcea0d0ac2bd775f0fb4c7e357a089979370ae3cd (patch)
treefaa0e678f606971b55ef795d507d613d40e93de2 /tests/algorithm_tests.cpp
parent6a75903c79ff7109c24d281372005b622a9d9177 (diff)
downloadplatform_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/algorithm_tests.cpp')
-rw-r--r--tests/algorithm_tests.cpp51
1 files changed, 31 insertions, 20 deletions
diff --git a/tests/algorithm_tests.cpp b/tests/algorithm_tests.cpp
index 388d17d..368b53d 100644
--- a/tests/algorithm_tests.cpp
+++ b/tests/algorithm_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, CHE...
#include <gsl/gsl_algorithm> // for copy
@@ -29,6 +35,8 @@ struct fail_fast;
using namespace std;
using namespace gsl;
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute
TEST_CASE("same_type")
{
// dynamic source and destination span
@@ -36,8 +44,8 @@ TEST_CASE("same_type")
std::array<int, 5> src{1, 2, 3, 4, 5};
std::array<int, 10> dst{};
- span<int> src_span(src);
- span<int> dst_span(dst);
+ const span<int> src_span(src);
+ const span<int> dst_span(dst);
copy(src_span, dst_span);
copy(src_span, dst_span.subspan(src_span.size()));
@@ -53,8 +61,8 @@ TEST_CASE("same_type")
std::array<int, 5> src{1, 2, 3, 4, 5};
std::array<int, 10> dst{};
- span<int, 5> src_span(src);
- span<int> dst_span(dst);
+ const span<int, 5> src_span(src);
+ const span<int> dst_span(dst);
copy(src_span, dst_span);
copy(src_span, dst_span.subspan(src_span.size()));
@@ -70,8 +78,8 @@ TEST_CASE("same_type")
std::array<int, 5> src{1, 2, 3, 4, 5};
std::array<int, 10> dst{};
- span<int> src_span(src);
- span<int, 10> dst_span(dst);
+ const span<int> src_span(src);
+ const span<int, 10> dst_span(dst);
copy(src_span, dst_span);
copy(src_span, dst_span.subspan(src_span.size()));
@@ -87,8 +95,8 @@ TEST_CASE("same_type")
std::array<int, 5> src{1, 2, 3, 4, 5};
std::array<int, 10> dst{};
- span<int, 5> src_span(src);
- span<int, 10> dst_span(dst);
+ const span<int, 5> src_span(src);
+ const span<int, 10> dst_span(dst);
copy(src_span, dst_span);
copy(src_span, dst_span.subspan(src_span.size()));
@@ -100,6 +108,9 @@ TEST_CASE("same_type")
}
}
+
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute
TEST_CASE("compatible_type")
{
// dynamic source and destination span
@@ -107,8 +118,8 @@ TEST_CASE("compatible_type")
std::array<short, 5> src{1, 2, 3, 4, 5};
std::array<int, 10> dst{};
- span<short> src_span(src);
- span<int> dst_span(dst);
+ const span<short> src_span(src);
+ const span<int> dst_span(dst);
copy(src_span, dst_span);
copy(src_span, dst_span.subspan(src_span.size()));
@@ -124,8 +135,8 @@ TEST_CASE("compatible_type")
std::array<short, 5> src{1, 2, 3, 4, 5};
std::array<int, 10> dst{};
- span<short, 5> src_span(src);
- span<int> dst_span(dst);
+ const span<short, 5> src_span(src);
+ const span<int> dst_span(dst);
copy(src_span, dst_span);
copy(src_span, dst_span.subspan(src_span.size()));
@@ -141,8 +152,8 @@ TEST_CASE("compatible_type")
std::array<short, 5> src{1, 2, 3, 4, 5};
std::array<int, 10> dst{};
- span<short> src_span(src);
- span<int, 10> dst_span(dst);
+ const span<short> src_span(src);
+ const span<int, 10> dst_span(dst);
copy(src_span, dst_span);
copy(src_span, dst_span.subspan(src_span.size()));
@@ -158,8 +169,8 @@ TEST_CASE("compatible_type")
std::array<short, 5> src{1, 2, 3, 4, 5};
std::array<int, 10> dst{};
- span<short, 5> src_span(src);
- span<int, 10> dst_span(dst);
+ const span<short, 5> src_span(src);
+ const span<int, 10> dst_span(dst);
copy(src_span, dst_span);
copy(src_span, dst_span.subspan(src_span.size()));
@@ -195,10 +206,10 @@ TEST_CASE("small_destination_span")
std::array<int, 12> src{1, 2, 3, 4};
std::array<int, 4> dst{};
- span<int> src_span_dyn(src);
- span<int, 12> src_span_static(src);
- span<int> dst_span_dyn(dst);
- span<int, 4> dst_span_static(dst);
+ const span<int> src_span_dyn(src);
+ const span<int, 12> src_span_static(src);
+ const span<int> dst_span_dyn(dst);
+ const span<int, 4> dst_span_static(dst);
CHECK_THROWS_AS(copy(src_span_dyn, dst_span_dyn), fail_fast);
CHECK_THROWS_AS(copy(src_span_dyn, dst_span_static), fail_fast);