aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/algorithm_tests.cpp51
-rw-r--r--tests/assertion_tests.cpp6
-rw-r--r--tests/at_tests.cpp21
-rw-r--r--tests/bounds_tests.cpp16
-rw-r--r--tests/byte_tests.cpp24
-rw-r--r--tests/multi_span_tests.cpp224
-rw-r--r--tests/no_exception_ensure_tests.cpp8
-rw-r--r--tests/no_exception_throw_tests.cpp4
-rw-r--r--tests/notnull_tests.cpp39
-rw-r--r--tests/owner_tests.cpp11
-rw-r--r--tests/span_tests.cpp88
-rw-r--r--tests/strided_span_tests.cpp38
-rw-r--r--tests/string_span_tests.cpp55
-rw-r--r--tests/test.cpp8
-rw-r--r--tests/utils_tests.cpp9
16 files changed, 471 insertions, 135 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b5e9bb2..5149d2f 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -27,7 +27,7 @@ else()
endif()
if (MSVC AND (GSL_CXX_STANDARD EQUAL 17))
- set(GSL_CPLUSPLUS_OPT -Zc:__cplusplus)
+ set(GSL_CPLUSPLUS_OPT -Zc:__cplusplus -permissive-)
endif()
# this interface adds compile options to how the tests are run
@@ -49,6 +49,7 @@ target_compile_options(gsl_tests_config INTERFACE
-Werror
-Wextra
-Wno-missing-braces
+ -Wno-unknown-attributes
-Wnon-virtual-dtor
-Wold-style-cast
-Woverloaded-virtual
@@ -138,6 +139,7 @@ target_compile_options(gsl_tests_config_noexcept INTERFACE
-Werror
-Wextra
-Wno-missing-braces
+ -Wno-unknown-attributes
-Wnon-virtual-dtor
-Wold-style-cast
-Woverloaded-virtual
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);
diff --git a/tests/assertion_tests.cpp b/tests/assertion_tests.cpp
index 25c0089..0c509ad 100644
--- a/tests/assertion_tests.cpp
+++ b/tests/assertion_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, CHECK...
#include <gsl/gsl_assert> // for fail_fast (ptr only), Ensures, Expects
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
+
diff --git a/tests/bounds_tests.cpp b/tests/bounds_tests.cpp
index 1f4b1e2..e586d44 100644
--- a/tests/bounds_tests.cpp
+++ b/tests/bounds_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, TEST_CASE
#include <gsl/multi_span> // for static_bounds, static_bounds_dynamic_range_t
@@ -32,6 +38,7 @@ namespace
void use(std::ptrdiff_t&) {}
}
+GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
TEST_CASE("basic_bounds")
{
for (auto point : static_bounds<dynamic_range, 3, 4>{2}) {
@@ -44,6 +51,8 @@ TEST_CASE("basic_bounds")
}
}
+GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("bounds_basic")
{
static_bounds<3, 4, 5> b;
@@ -53,6 +62,8 @@ TEST_CASE("bounds_basic")
x.slice().slice();
}
+GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("arrayview_iterator")
{
static_bounds<4, dynamic_range, 2> bounds{3};
@@ -71,6 +82,7 @@ TEST_CASE("arrayview_iterator")
#endif
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("bounds_convertible")
{
static_bounds<7, 4, 2> b1;
@@ -97,3 +109,7 @@ TEST_CASE("bounds_convertible")
CHECK(b5 == b6);
CHECK(b5.size() == b6.size());
}
+
+#ifdef CONFIRM_COMPILATION_ERRORS
+copy(src_span_static, dst_span_static);
+#endif
diff --git a/tests/byte_tests.cpp b/tests/byte_tests.cpp
index 41501ce..d6634bb 100644
--- a/tests/byte_tests.cpp
+++ b/tests/byte_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, TEST_...
#include <gsl/gsl_byte> // for to_byte, to_integer, byte, operator&, ope...
@@ -23,7 +29,6 @@ using namespace gsl;
namespace
{
-
TEST_CASE("construction")
{
{
@@ -31,6 +36,7 @@ TEST_CASE("construction")
CHECK(static_cast<unsigned char>(b) == 4);
}
+ GSL_SUPPRESS(es.49)
{
const byte b = byte(12);
CHECK(static_cast<unsigned char>(b) == 12);
@@ -46,11 +52,12 @@ TEST_CASE("construction")
CHECK(static_cast<unsigned char>(b) == 12);
}
- // waiting for C++17 enum class direct initializer support
- //{
- // byte b { 14 };
- // CHECK(static_cast<unsigned char>(b) == 14);
- //}
+#if defined(__cplusplus) && (__cplusplus >= 201703L)
+ {
+ const byte b { 14 };
+ CHECK(static_cast<unsigned char>(b) == 14);
+ }
+#endif
}
TEST_CASE("bitwise_operations")
@@ -114,6 +121,7 @@ int modify_both(gsl::byte & b, int& i)
return i;
}
+GSL_SUPPRESS(type.1)
TEST_CASE("aliasing")
{
int i{0};
@@ -122,3 +130,7 @@ TEST_CASE("aliasing")
}
}
+
+#ifdef CONFIRM_COMPILATION_ERRORS
+copy(src_span_static, dst_span_static);
+#endif
diff --git a/tests/multi_span_tests.cpp b/tests/multi_span_tests.cpp
index 549dcbe..9c05cb4 100644
--- a/tests/multi_span_tests.cpp
+++ b/tests/multi_span_tests.cpp
@@ -14,6 +14,13 @@
//
///////////////////////////////////////////////////////////////////////////////
+#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, CHECK...
#include <gsl/gsl_byte> // for byte
@@ -29,9 +36,10 @@
#include <string> // for string
#include <vector> // for vector
-namespace gsl {
+namespace gsl
+{
struct fail_fast;
-} // namespace gsl
+} // namespace gsl
using namespace std;
using namespace gsl;
@@ -44,8 +52,9 @@ struct BaseClass
struct DerivedClass : BaseClass
{
};
-}
+} // namespace
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("default_constructor")
{
{
@@ -80,6 +89,7 @@ TEST_CASE("default_constructor")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_nullptr_constructor")
{
{
@@ -122,8 +132,8 @@ TEST_CASE("from_nullptr_constructor")
}
}
-TEST_CASE("from_nullptr_length_constructor")
-{
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+TEST_CASE("from_nullptr_length_constructor") {
{
multi_span<int> s{nullptr, 0};
CHECK((s.length() == 0 && s.data() == nullptr));
@@ -141,25 +151,18 @@ TEST_CASE("from_nullptr_length_constructor")
}
{
-#ifdef CONFIRM_COMPILATION_ERRORS
- multi_span<int, 1> s{nullptr, 0};
- CHECK((s.length() == 1 && s.data() == nullptr)); // explains why it can't compile
-#endif
- }
-
- {
- auto workaround_macro = []() { multi_span<int> s{nullptr, 1}; };
+ auto workaround_macro = []() { const multi_span<int> s{nullptr, 1}; };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
- auto const_workaround_macro = []() { multi_span<const int> cs{nullptr, 1}; };
+ auto const_workaround_macro = []() { const multi_span<const int> cs{nullptr, 1}; };
CHECK_THROWS_AS(const_workaround_macro(), fail_fast);
}
{
- auto workaround_macro = []() { multi_span<int, 0> s{nullptr, 1}; };
+ auto workaround_macro = []() { const multi_span<int, 0> s{nullptr, 1}; };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
- auto const_workaround_macro = []() { multi_span<const int, 0> s{nullptr, 1}; };
+ auto const_workaround_macro = []() { const multi_span<const int, 0> s{nullptr, 1}; };
CHECK_THROWS_AS(const_workaround_macro(), fail_fast);
}
@@ -170,8 +173,16 @@ TEST_CASE("from_nullptr_length_constructor")
multi_span<const int*> cs{nullptr, 0};
CHECK((cs.length() == 0 && cs.data() == nullptr));
}
+
+ {
+#ifdef CONFIRM_COMPILATION_ERRORS
+ multi_span<int, 1> s{nullptr, 0};
+ CHECK((s.length() == 1 && s.data() == nullptr)); // explains why it can't compile
+#endif
+ }
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_element_constructor")
{
int i = 5;
@@ -222,6 +233,7 @@ TEST_CASE("from_element_constructor")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_pointer_length_constructor")
{
int arr[4] = {1, 2, 3, 4};
@@ -246,11 +258,12 @@ TEST_CASE("from_pointer_length_constructor")
{
int* p = nullptr;
- auto workaround_macro = [=]() { multi_span<int> s{p, 2}; };
+ auto workaround_macro = [=]() { const multi_span<int> s{p, 2}; };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_pointer_pointer_constructor")
{
int arr[4] = {1, 2, 3, 4};
@@ -278,29 +291,31 @@ TEST_CASE("from_pointer_pointer_constructor")
}
{
- auto workaround_macro = [&]() { multi_span<int> s{&arr[1], &arr[0]}; };
+ auto workaround_macro = [&]() { const multi_span<int> s{&arr[1], &arr[0]}; };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
{
int* p = nullptr;
- auto workaround_macro = [&]() { multi_span<int> s{&arr[0], p}; };
+ auto workaround_macro = [&]() { const multi_span<int> s{&arr[0], p}; };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
{
int* p = nullptr;
- auto workaround_macro = [&]() { multi_span<int> s{p, p}; };
+ auto workaround_macro = [&]() { const multi_span<int> s{p, p}; };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
{
int* p = nullptr;
- auto workaround_macro = [&]() { multi_span<int> s{&arr[0], p}; };
+ auto workaround_macro = [&]() { const multi_span<int> s{&arr[0], p}; };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
TEST_CASE("from_array_constructor")
{
int arr[5] = {1, 2, 3, 4, 5};
@@ -425,6 +440,11 @@ TEST_CASE("from_array_constructor")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(i.11) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
TEST_CASE("from_dynamic_array_constructor")
{
double(*arr)[3][4] = new double[100][3][4];
@@ -453,6 +473,7 @@ TEST_CASE("from_dynamic_array_constructor")
delete[] arr;
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: Attribute
TEST_CASE("from_std_array_constructor")
{
std::array<int, 4> arr = {1, 2, 3, 4};
@@ -512,6 +533,7 @@ TEST_CASE("from_std_array_constructor")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_const_std_array_constructor")
{
const std::array<int, 4> arr = {1, 2, 3, 4};
@@ -559,6 +581,7 @@ TEST_CASE("from_const_std_array_constructor")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_container_constructor")
{
std::vector<int> v = {1, 2, 3};
@@ -589,8 +612,7 @@ TEST_CASE("from_container_constructor")
multi_span<char> s{cstr};
#endif
multi_span<const char> cs{cstr};
- CHECK((cs.size() == narrow_cast<std::ptrdiff_t>(cstr.size()) &&
- cs.data() == cstr.data()));
+ CHECK((cs.size() == narrow_cast<std::ptrdiff_t>(cstr.size()) && cs.data() == cstr.data()));
}
{
@@ -633,6 +655,8 @@ TEST_CASE("from_container_constructor")
}
}
+GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_convertible_span_constructor")
{
#ifdef CONFIRM_COMPILATION_ERRORS
@@ -660,6 +684,7 @@ TEST_CASE("from_convertible_span_constructor")
(void) avcd;
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("copy_move_and_assignment")
{
multi_span<int> s1;
@@ -688,6 +713,8 @@ void fn(const Bounds&)
{
static_assert(Bounds::static_size == 60, "static bounds is wrong size");
}
+
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("as_multi_span_reshape")
{
int a[3][4][5];
@@ -706,11 +733,10 @@ TEST_CASE("as_multi_span_reshape")
auto av8 = as_multi_span<int>(av7);
CHECK(av8.size() == av6.size());
- for (auto i = 0; i < av8.size(); i++) {
- CHECK(av8[i] == 1);
- }
+ for (auto i = 0; i < av8.size(); i++) { CHECK(av8[i] == 1); }
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("first")
{
int arr[5] = {1, 2, 3, 4, 5};
@@ -754,6 +780,7 @@ TEST_CASE("first")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("last")
{
int arr[5] = {1, 2, 3, 4, 5};
@@ -796,6 +823,7 @@ TEST_CASE("last")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("subspan")
{
int arr[5] = {1, 2, 3, 4, 5};
@@ -869,6 +897,7 @@ TEST_CASE("subspan")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("rank")
{
int arr[2] = {1, 2};
@@ -890,6 +919,7 @@ TEST_CASE("rank")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("extent")
{
{
@@ -962,6 +992,7 @@ TEST_CASE("operator_function_call")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("comparison_operators")
{
{
@@ -1074,17 +1105,20 @@ TEST_CASE("comparison_operators")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(i.11) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
TEST_CASE("basics")
{
auto ptr = as_multi_span(new int[10], 10);
fill(ptr.begin(), ptr.end(), 99);
- for (int num : ptr) {
- CHECK(num == 99);
- }
+ for (int num : ptr) { CHECK(num == 99); }
delete[] ptr.data();
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
TEST_CASE("bounds_checks")
{
int arr[10][2];
@@ -1111,25 +1145,24 @@ TEST_CASE("bounds_checks")
void overloaded_func(multi_span<const int, dynamic_range, 3, 5> exp, int expected_value)
{
- for (auto val : exp) {
- CHECK(val == expected_value);
- }
+ for (auto val : exp) { CHECK(val == expected_value); }
}
void overloaded_func(multi_span<const char, dynamic_range, 3, 5> exp, char expected_value)
{
- for (auto val : exp) {
- CHECK(val == expected_value);
- }
+ for (auto val : exp) { CHECK(val == expected_value); }
}
void fixed_func(multi_span<int, 3, 3, 5> exp, int expected_value)
{
- for (auto val : exp) {
- CHECK(val == expected_value);
- }
+ for (auto val : exp) { CHECK(val == expected_value); }
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.3) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.5) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.5) // NO-FORMAT: attribute
TEST_CASE("span_parameter_test")
{
auto data = new int[4][3][5];
@@ -1151,12 +1184,16 @@ TEST_CASE("span_parameter_test")
delete[] data;
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute // false positive, checker does not recognize multi_span yet
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.3) // NO-FORMAT: attribute
TEST_CASE("md_access")
{
auto width = 5, height = 20;
auto imgSize = width * height;
- auto image_ptr = new int[static_cast<std::size_t>(imgSize)][3];
+ auto image_ptr = new int[narrow_cast<std::size_t>(imgSize)][3];
// size check will be done
auto image_view =
@@ -1165,8 +1202,10 @@ TEST_CASE("md_access")
iota(image_view.begin(), image_view.end(), 1);
int expected = 0;
- for (auto i = 0; i < height; i++) {
- for (auto j = 0; j < width; j++) {
+ for (auto i = 0; i < height; i++)
+ {
+ for (auto j = 0; j < width; j++)
+ {
CHECK(expected + 1 == image_view[i][j][0]);
CHECK(expected + 2 == image_view[i][j][1]);
CHECK(expected + 3 == image_view[i][j][2]);
@@ -1183,6 +1222,11 @@ TEST_CASE("md_access")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
+GSL_SUPPRESS(i.11) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.3) // NO-FORMAT: attribute
TEST_CASE("as_multi_span")
{
{
@@ -1201,6 +1245,7 @@ TEST_CASE("as_multi_span")
string str = "ttttttttttttttt"; // size = 15
auto t = str.data();
+ GSL_SUPPRESS(type.4) // NO-FORMAT: attribute // TODO: false positive
(void) t;
auto av3 = as_multi_span(str);
overloaded_func(as_multi_span(av3, dim(1), dim<3>(), dim<5>()), 't');
@@ -1232,12 +1277,13 @@ TEST_CASE("as_multi_span")
auto dv = as_multi_span(vec);
(void) dv;
-#ifdef CONFIRM_COMPILATION_ERRORS
+ #ifdef CONFIRM_COMPILATION_ERRORS
auto dv2 = as_multi_span(std::move(vec));
-#endif
+ #endif
}
}
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
TEST_CASE("empty_spans")
{
{
@@ -1247,7 +1293,8 @@ TEST_CASE("empty_spans")
CHECK_THROWS_AS(empty_av[0], fail_fast);
CHECK_THROWS_AS(empty_av.begin()[0], fail_fast);
CHECK_THROWS_AS(empty_av.cbegin()[0], fail_fast);
- for (auto& v : empty_av) {
+ for (auto& v : empty_av)
+ {
(void) v;
CHECK(false);
}
@@ -1259,17 +1306,25 @@ TEST_CASE("empty_spans")
CHECK_THROWS_AS(empty_av[0], fail_fast);
CHECK_THROWS_AS(empty_av.begin()[0], fail_fast);
CHECK_THROWS_AS(empty_av.cbegin()[0], fail_fast);
- for (auto& v : empty_av) {
+ for (auto& v : empty_av)
+ {
(void) v;
CHECK(false);
}
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.3) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.5) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
TEST_CASE("index_constructor")
{
auto arr = new int[8];
- for (int i = 0; i < 4; ++i) {
+ for (int i = 0; i < 4; ++i)
+ {
arr[2 * i] = 4 + i;
arr[2 * i + 1] = i;
}
@@ -1291,6 +1346,7 @@ TEST_CASE("index_constructor")
delete[] arr;
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("index_constructors")
{
{
@@ -1352,17 +1408,18 @@ TEST_CASE("index_constructors")
CHECK(i9[0] == 0);
}
- #ifdef CONFIRM_COMPILATION_ERRORS
+#ifdef CONFIRM_COMPILATION_ERRORS
{
- multi_span_index<3> i1(0, 1);
- multi_span_index<3> i2(0, 1, 2, 3);
- multi_span_index<3> i3 = {0};
- multi_span_index<3> i4 = {0, 1, 2, 3};
- multi_span_index<1> i5 = {0, 1};
+ multi_span_index<3> i1(0, 1);
+ multi_span_index<3> i2(0, 1, 2, 3);
+ multi_span_index<3> i3 = {0};
+ multi_span_index<3> i4 = {0, 1, 2, 3};
+ multi_span_index<1> i5 = {0, 1};
}
- #endif
+#endif
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("index_operations")
{
ptrdiff_t a[3] = {0, 1, 2};
@@ -1418,6 +1475,8 @@ TEST_CASE("index_operations")
}
}
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
void iterate_second_column(multi_span<int, dynamic_range, dynamic_range> av)
{
auto length = av.size() / 2;
@@ -1426,33 +1485,33 @@ void iterate_second_column(multi_span<int, dynamic_range, dynamic_range> av)
auto section = av.section({0, 1}, {length, 1});
CHECK(section.size() == length);
- for (auto i = 0; i < section.size(); ++i) {
- CHECK(section[i][0] == av[i][1]);
- }
+ for (auto i = 0; i < section.size(); ++i) { CHECK(section[i][0] == av[i][1]); }
- for (auto i = 0; i < section.size(); ++i) {
+ for (auto i = 0; i < section.size(); ++i)
+ {
auto idx = multi_span_index<2>{i, 0}; // avoid braces inside the CHECK macro
CHECK(section[idx] == av[i][1]);
}
CHECK(section.bounds().index_bounds()[0] == length);
CHECK(section.bounds().index_bounds()[1] == 1);
- for (auto i = 0; i < section.bounds().index_bounds()[0]; ++i) {
- for (auto j = 0; j < section.bounds().index_bounds()[1]; ++j) {
+ for (auto i = 0; i < section.bounds().index_bounds()[0]; ++i)
+ {
+ for (auto j = 0; j < section.bounds().index_bounds()[1]; ++j)
+ {
auto idx = multi_span_index<2>{i, j}; // avoid braces inside the CHECK macro
CHECK(section[idx] == av[i][1]);
}
}
auto check_sum = 0;
- for (auto i = 0; i < length; ++i) {
- check_sum += av[i][1];
- }
+ for (auto i = 0; i < length; ++i) { check_sum += av[i][1]; }
{
auto idx = 0;
auto sum = 0;
- for (auto num : section) {
+ for (auto num : section)
+ {
CHECK(num == av[idx][1]);
sum += num;
idx++;
@@ -1463,7 +1522,8 @@ void iterate_second_column(multi_span<int, dynamic_range, dynamic_range> av)
{
auto idx = length - 1;
auto sum = 0;
- for (auto iter = section.rbegin(); iter != section.rend(); ++iter) {
+ for (auto iter = section.rbegin(); iter != section.rend(); ++iter)
+ {
CHECK(*iter == av[idx][1]);
sum += *iter;
idx--;
@@ -1473,6 +1533,7 @@ void iterate_second_column(multi_span<int, dynamic_range, dynamic_range> av)
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("span_section_iteration")
{
int arr[4][2] = {{4, 0}, {5, 1}, {6, 2}, {7, 3}};
@@ -1499,15 +1560,18 @@ TEST_CASE("span_section_iteration")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.3) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.5) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
TEST_CASE("dynamic_span_section_iteration")
{
auto height = 4, width = 2;
auto size = height * width;
- auto arr = new int[static_cast<std::size_t>(size)];
- for (auto i = 0; i < size; ++i) {
- arr[i] = i;
- }
+ auto arr = new int[narrow_cast<std::size_t>(size)];
+ for (auto i = 0; i < size; ++i) { arr[i] = i; }
auto av = as_multi_span(arr, size);
@@ -1531,6 +1595,10 @@ TEST_CASE("dynamic_span_section_iteration")
delete[] arr;
}
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
+GSL_SUPPRESS(i.11) // NO-FORMAT: attribute
TEST_CASE("span_structure_size")
{
double(*arr)[3][4] = new double[100][3][4];
@@ -1550,6 +1618,7 @@ TEST_CASE("span_structure_size")
(void) av2;
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("fixed_size_conversions")
{
int arr[] = {1, 2, 3, 4};
@@ -1631,7 +1700,7 @@ TEST_CASE("fixed_size_conversions")
#endif
{
auto f = [&]() {
- multi_span<int, 4> av9 = {arr2, 2};
+ const multi_span<int, 4> av9 = {arr2, 2};
(void) av9;
};
CHECK_THROWS_AS(f(), fail_fast);
@@ -1640,12 +1709,13 @@ TEST_CASE("fixed_size_conversions")
// this should fail - we are trying to assign a small dynamic a_v to a fixed_size larger one
multi_span<int, dynamic_range> av = arr2;
auto f = [&]() {
- multi_span<int, 4> av2 = av;
+ const multi_span<int, 4> av2 = av;
(void) av2;
};
CHECK_THROWS_AS(f(), fail_fast);
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("as_writeable_bytes")
{
int a[] = {1, 2, 3, 4};
@@ -1674,6 +1744,10 @@ TEST_CASE("as_writeable_bytes")
}
}
+
+GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("iterator")
{
int a[] = {1, 2, 3, 4};
@@ -1682,8 +1756,14 @@ TEST_CASE("iterator")
multi_span<int, dynamic_range> av = a;
auto wav = as_writeable_bytes(av);
for (auto& b : wav) {
+#if defined(__cplusplus) && (__cplusplus >= 201703L)
+ b = byte{0};
+#else
+ GSL_SUPPRESS(es.49)
b = byte(0);
+#endif
}
+
for (std::size_t i = 0; i < 4; ++i) {
CHECK(a[i] == 0);
}
@@ -1699,3 +1779,7 @@ TEST_CASE("iterator")
}
}
}
+
+#ifdef CONFIRM_COMPILATION_ERRORS
+copy(src_span_static, dst_span_static);
+#endif \ No newline at end of file
diff --git a/tests/no_exception_ensure_tests.cpp b/tests/no_exception_ensure_tests.cpp
index 5da021e..3a7f007 100644
--- a/tests/no_exception_ensure_tests.cpp
+++ b/tests/no_exception_ensure_tests.cpp
@@ -17,10 +17,10 @@
#include <cstdlib> // for std::exit
#include <gsl/span> // for span
-int operator_subscript_no_throw()
+int operator_subscript_no_throw() noexcept
{
int arr[10];
- gsl::span<int> sp { arr };
+ const gsl::span<int> sp { arr };
return sp[11];
}
@@ -30,7 +30,7 @@ void test_terminate()
std::exit(0);
}
-void setup_termination_handler()
+void setup_termination_handler() noexcept
{
#if defined(_MSC_VER)
@@ -45,7 +45,7 @@ void setup_termination_handler()
}
-int main()
+int main() noexcept
{
setup_termination_handler();
operator_subscript_no_throw();
diff --git a/tests/no_exception_throw_tests.cpp b/tests/no_exception_throw_tests.cpp
index dd4e994..9c491a6 100644
--- a/tests/no_exception_throw_tests.cpp
+++ b/tests/no_exception_throw_tests.cpp
@@ -19,7 +19,7 @@
int narrow_no_throw()
{
- long long bigNumber = 0x0fffffffffffffff;
+ const long long bigNumber = 0x0fffffffffffffff;
return gsl::narrow<int>(bigNumber);
}
@@ -28,7 +28,7 @@ void test_terminate()
std::exit(0);
}
-void setup_termination_handler()
+void setup_termination_handler() noexcept
{
#if defined(_MSC_VER)
diff --git a/tests/notnull_tests.cpp b/tests/notnull_tests.cpp
index 1cb9c10..e522fb5 100644
--- a/tests/notnull_tests.cpp
+++ b/tests/notnull_tests.cpp
@@ -14,6 +14,13 @@
//
///////////////////////////////////////////////////////////////////////////////
+#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, TEST_...
#include <gsl/pointers> // for not_null, operator<, operator<=, operator>
@@ -63,6 +70,7 @@ struct CustomPtr
template <typename T, typename U>
std::string operator==(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
{
+ GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
return reinterpret_cast<const void*>(lhs.p_) == reinterpret_cast<const void*>(rhs.p_) ? "true"
: "false";
}
@@ -70,6 +78,7 @@ std::string operator==(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
template <typename T, typename U>
std::string operator!=(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
{
+ GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
return reinterpret_cast<const void*>(lhs.p_) != reinterpret_cast<const void*>(rhs.p_) ? "true"
: "false";
}
@@ -77,6 +86,7 @@ std::string operator!=(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
template <typename T, typename U>
std::string operator<(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
{
+ GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
return reinterpret_cast<const void*>(lhs.p_) < reinterpret_cast<const void*>(rhs.p_) ? "true"
: "false";
}
@@ -84,6 +94,7 @@ std::string operator<(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
template <typename T, typename U>
std::string operator>(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
{
+ GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
return reinterpret_cast<const void*>(lhs.p_) > reinterpret_cast<const void*>(rhs.p_) ? "true"
: "false";
}
@@ -91,6 +102,7 @@ std::string operator>(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
template <typename T, typename U>
std::string operator<=(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
{
+ GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
return reinterpret_cast<const void*>(lhs.p_) <= reinterpret_cast<const void*>(rhs.p_) ? "true"
: "false";
}
@@ -98,6 +110,7 @@ std::string operator<=(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
template <typename T, typename U>
std::string operator>=(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
{
+ GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
return reinterpret_cast<const void*>(lhs.p_) >= reinterpret_cast<const void*>(rhs.p_) ? "true"
: "false";
}
@@ -111,9 +124,19 @@ struct NonCopyableNonMovable
NonCopyableNonMovable& operator=(NonCopyableNonMovable&&) = delete;
};
-bool helper(not_null<int*> p) { return *p == 12; }
-bool helper_const(not_null<const int*> p) { return *p == 12; }
+GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
+bool helper(not_null<int*> p)
+{
+ return *p == 12;
+}
+
+GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
+bool helper_const(not_null<const int*> p)
+{
+ return *p == 12;
+}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestNotNullConstructors")
{
#ifdef CONFIRM_COMPILATION_ERRORS
@@ -143,6 +166,7 @@ TEST_CASE("TestNotNullConstructors")
}
template<typename T>
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
void ostream_helper(T v)
{
not_null<T*> p(&v);
@@ -173,7 +197,8 @@ TEST_CASE("TestNotNullostream")
ostream_helper<std::string>("string");
}
-
+GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestNotNullCasting")
{
MyBase base;
@@ -236,6 +261,7 @@ TEST_CASE("TestNotNullRawPointerComparison")
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestNotNullDereferenceOperator")
{
{
@@ -297,6 +323,7 @@ TEST_CASE("TestNotNullSharedPtrComparison")
CHECK((NotNullSp2(sp2) >= NotNullSp1(sp1)) == (sp2 >= sp1));
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestNotNullCustomPtrComparison")
{
int ints[2] = {42, 43};
@@ -331,6 +358,8 @@ TEST_CASE("TestNotNullCustomPtrComparison")
#if defined(__cplusplus) && (__cplusplus >= 201703L)
+
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestNotNullConstructorTypeDeduction")
{
{
@@ -357,7 +386,7 @@ TEST_CASE("TestNotNullConstructorTypeDeduction")
{
auto workaround_macro = []() {
int* p1 = nullptr;
- not_null x{p1};
+ const not_null x{p1};
};
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
@@ -365,7 +394,7 @@ TEST_CASE("TestNotNullConstructorTypeDeduction")
{
auto workaround_macro = []() {
const int* p1 = nullptr;
- not_null x{p1};
+ const not_null x{p1};
};
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
diff --git a/tests/owner_tests.cpp b/tests/owner_tests.cpp
index 94822f5..9fff184 100644
--- a/tests/owner_tests.cpp
+++ b/tests/owner_tests.cpp
@@ -14,14 +14,25 @@
//
///////////////////////////////////////////////////////////////////////////////
+#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, TEST_...
#include <gsl/pointers> // for owner
using namespace gsl;
+GSL_SUPPRESS(f.23) // NO-FORMAT: attribute
void f(int* i) { *i += 1; }
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.3) // NO-FORMAT: attribute // TODO: false positive
+GSL_SUPPRESS(r.5) // NO-FORMAT: attribute
TEST_CASE("basic_test")
{
owner<int*> p = new int(120);
diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp
index 67c1b59..081221b 100644
--- a/tests/span_tests.cpp
+++ b/tests/span_tests.cpp
@@ -14,6 +14,13 @@
//
///////////////////////////////////////////////////////////////////////////////
+#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 26497) // from catch
+
+#endif
+
#include <catch/catch.hpp> // for AssertionHandler, StringRef, CHECK, TEST_...
#include <gsl/gsl_byte> // for byte
@@ -47,6 +54,7 @@ struct DerivedClass : BaseClass
};
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("default_constructor")
{
{
@@ -81,6 +89,7 @@ TEST_CASE("default_constructor")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("size_optimization")
{
{
@@ -94,56 +103,60 @@ TEST_CASE("size_optimization")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_nullptr_size_constructor")
{
{
- span<int> s{nullptr, static_cast<span<int>::index_type>(0)};
+ span<int> s{nullptr, narrow_cast<span<int>::index_type>(0)};
CHECK((s.size() == 0 && s.data() == nullptr));
- span<const int> cs{nullptr, static_cast<span<int>::index_type>(0)};
+ span<const int> cs{nullptr, narrow_cast<span<int>::index_type>(0)};
CHECK((cs.size() == 0 && cs.data() == nullptr));
}
{
- span<int, 0> s{nullptr, static_cast<span<int>::index_type>(0)};
+ span<int, 0> s{nullptr, narrow_cast<span<int>::index_type>(0)};
CHECK((s.size() == 0 && s.data() == nullptr));
- span<const int, 0> cs{nullptr, static_cast<span<int>::index_type>(0)};
+ span<const int, 0> cs{nullptr, narrow_cast<span<int>::index_type>(0)};
CHECK((cs.size() == 0 && cs.data() == nullptr));
}
{
auto workaround_macro = []() {
- span<int, 1> s{nullptr, static_cast<span<int>::index_type>(0)};
+ const span<int, 1> s{nullptr, narrow_cast<span<int>::index_type>(0)};
};
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
{
- auto workaround_macro = []() { span<int> s{nullptr, 1}; };
+ auto workaround_macro = []() { const span<int> s{nullptr, 1}; };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
- auto const_workaround_macro = []() { span<const int> cs{nullptr, 1}; };
+ auto const_workaround_macro = []() { const span<const int> cs{nullptr, 1}; };
CHECK_THROWS_AS(const_workaround_macro(), fail_fast);
}
{
- auto workaround_macro = []() { span<int, 0> s{nullptr, 1}; };
+ auto workaround_macro = []() { const span<int, 0> s{nullptr, 1}; };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
- auto const_workaround_macro = []() { span<const int, 0> s{nullptr, 1}; };
+ auto const_workaround_macro = []() { const span<const int, 0> s{nullptr, 1}; };
CHECK_THROWS_AS(const_workaround_macro(), fail_fast);
}
{
- span<int*> s{nullptr, static_cast<span<int>::index_type>(0)};
+ span<int*> s{nullptr, narrow_cast<span<int>::index_type>(0)};
CHECK((s.size() == 0 && s.data() == nullptr));
- span<const int*> cs{nullptr, static_cast<span<int>::index_type>(0)};
+ span<const int*> cs{nullptr, narrow_cast<span<int>::index_type>(0)};
CHECK((cs.size() == 0 && cs.data() == nullptr));
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute
TEST_CASE("from_pointer_length_constructor")
{
int arr[4] = {1, 2, 3, 4};
@@ -164,7 +177,7 @@ TEST_CASE("from_pointer_length_constructor")
}
}
{
- span<int> s = { &arr[i], 4-i };
+ span<int> s = { &arr[i], 4-narrow_cast<ptrdiff_t>(i) };
CHECK(s.size() == 4-i);
CHECK(s.data() == &arr[i]);
CHECK(s.empty() == (4-i == 0));
@@ -186,13 +199,13 @@ TEST_CASE("from_pointer_length_constructor")
{
int* p = nullptr;
- span<int> s{p, static_cast<span<int>::index_type>(0)};
+ span<int> s{p, narrow_cast<span<int>::index_type>(0)};
CHECK((s.size() == 0 && s.data() == nullptr));
}
{
int* p = nullptr;
- auto workaround_macro = [=]() { span<int> s{p, 2}; };
+ auto workaround_macro = [=]() { const span<int> s{p, 2}; };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
@@ -204,7 +217,7 @@ TEST_CASE("from_pointer_length_constructor")
{
int* p = nullptr;
- auto s = make_span(p, static_cast<span<int>::index_type>(0));
+ auto s = make_span(p, narrow_cast<span<int>::index_type>(0));
CHECK((s.size() == 0 && s.data() == nullptr));
}
@@ -215,6 +228,8 @@ TEST_CASE("from_pointer_length_constructor")
}
}
+
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_pointer_pointer_constructor")
{
int arr[4] = {1, 2, 3, 4};
@@ -291,6 +306,8 @@ TEST_CASE("from_pointer_pointer_constructor")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute // TODO: false positive?
TEST_CASE("from_array_constructor")
{
int arr[5] = {1, 2, 3, 4, 5};
@@ -333,7 +350,7 @@ TEST_CASE("from_array_constructor")
}
#endif
{
- span<int[3]> s{&(arr2d[0]), 1};
+ span<int[3]> s{&arr2d[0], 1};
CHECK((s.size() == 1 && s.data() == &arr2d[0]));
}
@@ -382,6 +399,10 @@ TEST_CASE("from_array_constructor")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
+GSL_SUPPRESS(i.11) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
TEST_CASE("from_dynamic_array_constructor")
{
double(*arr)[3][4] = new double[100][3][4];
@@ -399,6 +420,8 @@ TEST_CASE("from_dynamic_array_constructor")
delete[] arr;
}
+
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_std_array_constructor")
{
std::array<int, 4> arr = {1, 2, 3, 4};
@@ -478,6 +501,7 @@ TEST_CASE("from_std_array_constructor")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_const_std_array_constructor")
{
const std::array<int, 4> arr = {1, 2, 3, 4};
@@ -521,6 +545,7 @@ TEST_CASE("from_const_std_array_constructor")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_std_array_const_constructor")
{
std::array<const int, 4> arr = {1, 2, 3, 4};
@@ -561,6 +586,7 @@ TEST_CASE("from_std_array_const_constructor")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_container_constructor")
{
std::vector<int> v = {1, 2, 3};
@@ -653,6 +679,7 @@ TEST_CASE("from_container_constructor")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("from_convertible_span_constructor")
{
{
@@ -690,6 +717,7 @@ TEST_CASE("from_convertible_span_constructor")
#endif
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("copy_move_and_assignment")
{
span<int> s1;
@@ -711,6 +739,7 @@ TEST_CASE("copy_move_and_assignment")
CHECK((s1.size() == 2 && s1.data() == &arr[1]));
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("first")
{
int arr[5] = {1, 2, 3, 4, 5};
@@ -749,6 +778,7 @@ TEST_CASE("first")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("last")
{
int arr[5] = {1, 2, 3, 4, 5};
@@ -786,6 +816,7 @@ TEST_CASE("last")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("subspan")
{
int arr[5] = {1, 2, 3, 4, 5};
@@ -867,6 +898,7 @@ TEST_CASE("subspan")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("at_call")
{
int arr[4] = {1, 2, 3, 4};
@@ -886,6 +918,7 @@ TEST_CASE("at_call")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("operator_function_call")
{
int arr[4] = {1, 2, 3, 4};
@@ -905,6 +938,7 @@ TEST_CASE("operator_function_call")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("iterator_default_init")
{
span<int>::iterator it1;
@@ -912,6 +946,7 @@ TEST_CASE("iterator_default_init")
CHECK(it1 == it2);
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("const_iterator_default_init")
{
span<int>::const_iterator it1;
@@ -919,6 +954,7 @@ TEST_CASE("const_iterator_default_init")
CHECK(it1 == it2);
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("iterator_conversions")
{
span<int>::iterator badIt;
@@ -941,6 +977,7 @@ TEST_CASE("iterator_conversions")
CHECK(cit3 == s.cend());
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("iterator_comparisons")
{
int a[] = {1, 2, 3, 4};
@@ -988,6 +1025,7 @@ TEST_CASE("iterator_comparisons")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("begin_end")
{
{
@@ -1043,6 +1081,7 @@ TEST_CASE("begin_end")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("cbegin_cend")
{
{
@@ -1095,6 +1134,7 @@ TEST_CASE("cbegin_cend")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("rbegin_rend")
{
{
@@ -1137,6 +1177,7 @@ TEST_CASE("rbegin_rend")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("crbegin_crend")
{
{
@@ -1176,6 +1217,7 @@ TEST_CASE("crbegin_crend")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("comparison_operators")
{
{
@@ -1296,6 +1338,7 @@ TEST_CASE("comparison_operators")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("as_bytes")
{
int a[] = {1, 2, 3, 4};
@@ -1326,6 +1369,7 @@ TEST_CASE("as_bytes")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("as_writeable_bytes")
{
int a[] = {1, 2, 3, 4};
@@ -1359,6 +1403,7 @@ TEST_CASE("as_writeable_bytes")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("fixed_size_conversions")
{
int arr[] = {1, 2, 3, 4};
@@ -1389,7 +1434,7 @@ TEST_CASE("fixed_size_conversions")
{
span<int> s = arr;
auto f = [&]() {
- span<int, 2> s2 = s;
+ const span<int, 2> s2 = s;
static_cast<void>(s2);
};
CHECK_THROWS_AS(f(), fail_fast);
@@ -1399,7 +1444,7 @@ TEST_CASE("fixed_size_conversions")
// you can convert statically
{
- const span<int, 2> s2 = {arr, 2};
+ const span<int, 2> s2 = {&arr[0], 2};
static_cast<void>(s2);
}
{
@@ -1428,7 +1473,7 @@ TEST_CASE("fixed_size_conversions")
#endif
{
auto f = [&]() {
- span<int, 4> _s4 = {arr2, 2};
+ const span<int, 4> _s4 = {arr2, 2};
static_cast<void>(_s4);
};
CHECK_THROWS_AS(f(), fail_fast);
@@ -1437,12 +1482,13 @@ TEST_CASE("fixed_size_conversions")
// this should fail - we are trying to assign a small dynamic span to a fixed_size larger one
span<int> av = arr2;
auto f = [&]() {
- span<int, 4> _s4 = av;
+ const span<int, 4> _s4 = av;
static_cast<void>(_s4);
};
CHECK_THROWS_AS(f(), fail_fast);
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("interop_with_std_regex")
{
char lat[] = {'1', '2', '3', '4', '5', '6', 'E', 'F', 'G'};
@@ -1466,6 +1512,7 @@ TEST_CASE("interop_with_std_regex")
CHECK(match[0].second == (f_it + 1));
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("interop_with_gsl_at")
{
int arr[5] = {1, 2, 3, 4, 5};
@@ -1479,3 +1526,4 @@ TEST_CASE("default_constructible")
CHECK((std::is_default_constructible<span<int, 0>>::value));
CHECK((!std::is_default_constructible<span<int, 42>>::value));
}
+
diff --git a/tests/strided_span_tests.cpp b/tests/strided_span_tests.cpp
index 8719336..42eff7a 100644
--- a/tests/strided_span_tests.cpp
+++ b/tests/strided_span_tests.cpp
@@ -14,6 +14,13 @@
//
///////////////////////////////////////////////////////////////////////////////
+#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, CHECK...
#include <gsl/gsl_byte> // for byte
@@ -71,6 +78,7 @@ TEST_CASE("span_section")
CHECK((av_section_2[{1, 0}] == 34));
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("strided_span_constructors")
{
// Check stride constructor
@@ -271,6 +279,7 @@ TEST_CASE("strided_span_constructors")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("strided_span_slice")
{
std::vector<int> data(5 * 10);
@@ -297,6 +306,7 @@ TEST_CASE("strided_span_slice")
CHECK(sav[4][9] == 49);
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("strided_span_column_major")
{
// strided_span may be used to accommodate more peculiar
@@ -329,6 +339,7 @@ TEST_CASE("strided_span_column_major")
CHECK((cm_sec[{2, 1}] == 15));
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("strided_span_bounds")
{
int arr[] = {0, 1, 2, 3};
@@ -445,6 +456,7 @@ TEST_CASE("strided_span_bounds")
#endif
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("strided_span_type_conversion")
{
int arr[] = {0, 1, 2, 3};
@@ -542,6 +554,8 @@ TEST_CASE("strided_span_type_conversion")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
TEST_CASE("empty_strided_spans")
{
{
@@ -574,6 +588,8 @@ TEST_CASE("empty_strided_spans")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
void iterate_every_other_element(multi_span<int, dynamic_range> av)
{
// pick every other element
@@ -599,6 +615,7 @@ void iterate_every_other_element(multi_span<int, dynamic_range> av)
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("strided_span_section_iteration")
{
int arr[8] = {4, 0, 5, 1, 6, 2, 7, 3};
@@ -616,6 +633,11 @@ TEST_CASE("strided_span_section_iteration")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.3) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.5) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
TEST_CASE("dynamic_strided_span_section_iteration")
{
auto arr = new int[8];
@@ -630,6 +652,9 @@ TEST_CASE("dynamic_strided_span_section_iteration")
delete[] arr;
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute // TODO: does not work
void iterate_second_slice(multi_span<int, dynamic_range, dynamic_range, dynamic_range> av)
{
const int expected[6] = {2, 3, 10, 11, 18, 19};
@@ -656,6 +681,9 @@ void iterate_second_slice(multi_span<int, dynamic_range, dynamic_range, dynamic_
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute
TEST_CASE("strided_span_section_iteration_3d")
{
int arr[3][4][2]{};
@@ -670,6 +698,11 @@ TEST_CASE("strided_span_section_iteration_3d")
}
}
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.3) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.5) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
TEST_CASE("dynamic_strided_span_section_iteration_3d")
{
const auto height = 12, width = 2;
@@ -702,6 +735,9 @@ TEST_CASE("dynamic_strided_span_section_iteration_3d")
delete[] arr;
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute
TEST_CASE("strided_span_conversion")
{
// get an multi_span of 'c' values from the list of X's
@@ -720,7 +756,7 @@ TEST_CASE("strided_span_conversion")
auto d1 = narrow_cast<int>(sizeof(int)) * 12 / d2;
// convert to 4x12 array of bytes
- auto av = as_multi_span(as_bytes(as_multi_span(arr, 4)), dim(d1), dim(d2));
+ auto av = as_multi_span(as_bytes(as_multi_span(&arr[0], 4)), dim(d1), dim(d2));
CHECK(av.bounds().index_bounds()[0] == 4);
CHECK(av.bounds().index_bounds()[1] == 12);
diff --git a/tests/string_span_tests.cpp b/tests/string_span_tests.cpp
index c0b5b19..fd3e3e6 100644
--- a/tests/string_span_tests.cpp
+++ b/tests/string_span_tests.cpp
@@ -14,6 +14,13 @@
//
///////////////////////////////////////////////////////////////////////////////
+#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, TEST_...
#include <gsl/gsl_assert> // for Expects, fail_fast (ptr only)
@@ -37,6 +44,8 @@ namespace generic
{
template <typename CharT>
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
+GSL_SUPPRESS(f.23) // NO-FORMAT: attribute
auto strlen(const CharT* s)
{
auto p = s;
@@ -45,13 +54,15 @@ auto strlen(const CharT* s)
}
template <typename CharT>
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
auto strnlen(const CharT* s, std::size_t n)
{
- return std::find(s, s + n, CharT(0)) - s;
+ return std::find(s, s + n, CharT{0}) - s;
}
} // namespace generic
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestLiteralConstruction")
{
cwstring_span<> v = ensure_z(L"Hello");
@@ -61,6 +72,7 @@ TEST_CASE("TestLiteralConstruction")
wstring_span<> v2 = ensure0(L"Hello");
#endif
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestConstructFromStdString")
{
@@ -69,6 +81,7 @@ TEST_CASE("TestConstructFromStdString")
CHECK(v.length() == static_cast<cstring_span<>::index_type>(s.length()));
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestConstructFromStdVector")
{
std::vector<char> vec(5, 'h');
@@ -76,6 +89,7 @@ TEST_CASE("TestConstructFromStdVector")
CHECK(v.length() == static_cast<string_span<>::index_type>(vec.size()));
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestStackArrayConstruction")
{
wchar_t stack_string[] = L"Hello";
@@ -101,6 +115,7 @@ TEST_CASE("TestStackArrayConstruction")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestConstructFromConstCharPointer")
{
const char* s = "Hello";
@@ -108,6 +123,7 @@ TEST_CASE("TestConstructFromConstCharPointer")
CHECK(v.length() == 5);
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestConversionToConst")
{
char stack_string[] = "Hello";
@@ -116,6 +132,7 @@ TEST_CASE("TestConversionToConst")
CHECK(v.length() == v2.length());
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestConversionFromConst")
{
char stack_string[] = "Hello";
@@ -127,6 +144,7 @@ TEST_CASE("TestConversionFromConst")
#endif
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestToString")
{
auto s = gsl::to_string(cstring_span<>{});
@@ -139,6 +157,7 @@ TEST_CASE("TestToString")
CHECK(s2.length() == 5);
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("TestToBasicString")
{
auto s = gsl::to_basic_string<char, std::char_traits<char>, ::std::allocator<char>>(
@@ -152,6 +171,8 @@ TEST_CASE("TestToBasicString")
CHECK(s2.length() == 5);
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
TEST_CASE("EqualityAndImplicitConstructors")
{
{
@@ -378,6 +399,8 @@ TEST_CASE("EqualityAndImplicitConstructors")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
TEST_CASE("ComparisonAndImplicitConstructors")
{
{
@@ -448,6 +471,12 @@ TEST_CASE("ComparisonAndImplicitConstructors")
CHECK(span >= string_span<>(vec));
}
}
+
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.11) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.3) // NO-FORMAT: attribute
+GSL_SUPPRESS(r.5) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
TEST_CASE("ConstrutorsEnsureZ")
{
// remove z from literals
@@ -478,6 +507,8 @@ TEST_CASE("ConstrutorsEnsureZ")
}
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
TEST_CASE("Constructors")
{
// creating cstring_span
@@ -884,6 +915,8 @@ czstring_span<> CreateTempName(string_span<> span)
return {ret};
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
TEST_CASE("zstring")
{
@@ -904,7 +937,7 @@ TEST_CASE("zstring")
char buf[1];
buf[0] = 'a';
- auto workaround_macro = [&]() { zstring_span<> zspan({buf, 1}); };
+ auto workaround_macro = [&]() { const zstring_span<> zspan({buf, 1}); };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
@@ -938,6 +971,8 @@ cwzstring_span<> CreateTempNameW(wstring_span<> span)
return {ret};
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
TEST_CASE("wzstring")
{
@@ -958,7 +993,7 @@ TEST_CASE("wzstring")
wchar_t buf[1];
buf[0] = L'a';
- const auto workaround_macro = [&]() { wzstring_span<> zspan({buf, 1}); };
+ const auto workaround_macro = [&]() { const wzstring_span<> zspan({buf, 1}); };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
@@ -992,6 +1027,8 @@ cu16zstring_span<> CreateTempNameU16(u16string_span<> span)
return {ret};
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
TEST_CASE("u16zstring")
{
@@ -1012,7 +1049,7 @@ TEST_CASE("u16zstring")
char16_t buf[1];
buf[0] = u'a';
- const auto workaround_macro = [&]() { u16zstring_span<> zspan({buf, 1}); };
+ const auto workaround_macro = [&]() { const u16zstring_span<> zspan({buf, 1}); };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
@@ -1046,6 +1083,8 @@ cu32zstring_span<> CreateTempNameU32(u32string_span<> span)
return {ret};
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
TEST_CASE("u32zstring")
{
@@ -1066,7 +1105,7 @@ TEST_CASE("u32zstring")
char32_t buf[1];
buf[0] = u'a';
- const auto workaround_macro = [&]() { u32zstring_span<> zspan({buf, 1}); };
+ const auto workaround_macro = [&]() { const u32zstring_span<> zspan({buf, 1}); };
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
@@ -1090,6 +1129,8 @@ TEST_CASE("Issue305")
CHECK(foo["bar"] == 1);
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
TEST_CASE("char16_t type")
{
gsl::cu16string_span<> ss1 = gsl::ensure_z(u"abc");
@@ -1131,6 +1172,8 @@ TEST_CASE("char16_t type")
CHECK(ss8 != ss9);
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
+GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
TEST_CASE("char32_t type")
{
gsl::cu32string_span<> ss1 = gsl::ensure_z(U"abc");
@@ -1168,6 +1211,7 @@ TEST_CASE("char32_t type")
CHECK(ss8 != ss9);
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("as_bytes")
{
cwzstring_span<> v(L"qwerty");
@@ -1177,6 +1221,7 @@ TEST_CASE("as_bytes")
CHECK(bs.size() == s.size_bytes());
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("as_writeable_bytes")
{
wchar_t buf[]{L"qwerty"};
diff --git a/tests/test.cpp b/tests/test.cpp
index bae194d..dbdebb6 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -15,4 +15,12 @@
///////////////////////////////////////////////////////////////////////////////
#define CATCH_CONFIG_MAIN
+
+#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 : 26401 26409 26415 26418 26426 26429 26432 26433 26434 26435 26436 26439 26440 26443 26444 26446 26447 26451 26460 26461 26466 26472 26481 26482 26485 26492 26493 26494 26495 26496 26497) // from catch
+#endif // _MSC_VER
+
#include <catch/catch.hpp>
diff --git a/tests/utils_tests.cpp b/tests/utils_tests.cpp
index 587b0a1..05f8d0f 100644
--- a/tests/utils_tests.cpp
+++ b/tests/utils_tests.cpp
@@ -14,6 +14,13 @@
//
///////////////////////////////////////////////////////////////////////////////
+#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, TEST_...
#include <gsl/gsl_util> // for narrow, finally, narrow_cast, narrowing_e...
@@ -85,6 +92,7 @@ TEST_CASE("finally_function_ptr")
CHECK(j == 1);
}
+GSL_SUPPRESS(con.4) // NO-FORMAT: attribute
TEST_CASE("narrow_cast")
{
int n = 120;
@@ -96,6 +104,7 @@ TEST_CASE("narrow_cast")
CHECK(uc == 44);
}
+GSL_SUPPRESS(con.5) // NO-FORMAT: attribute
TEST_CASE("narrow")
{
int n = 120;