From 8577033f13a05984824d5d3cd73bafbac1c28080 Mon Sep 17 00:00:00 2001 From: "Jordan Maples [MSFT]" <49793787+JordanMaples@users.noreply.github.com> Date: Thu, 19 Dec 2019 14:05:02 -0800 Subject: [PATCH] addressing comments --- tests/algorithm_tests.cpp | 14 ++++++++------ tests/assertion_tests.cpp | 11 ++++++----- tests/at_tests.cpp | 12 +++++++----- tests/bounds_tests.cpp | 11 ++++------- tests/byte_tests.cpp | 11 ++++++----- tests/multi_span_tests.cpp | 10 +++++----- tests/notnull_tests.cpp | 15 ++++++++------- tests/owner_tests.cpp | 7 ++++--- tests/span_tests.cpp | 13 ++++++++----- tests/strict_notnull_tests.cpp | 12 ++++++++---- tests/strided_span_tests.cpp | 17 +++++++---------- tests/string_span_tests.cpp | 12 ++++++++---- tests/utils_tests.cpp | 13 ++++++++----- 13 files changed, 87 insertions(+), 71 deletions(-) diff --git a/tests/algorithm_tests.cpp b/tests/algorithm_tests.cpp index e42a99d..c88a120 100644 --- a/tests/algorithm_tests.cpp +++ b/tests/algorithm_tests.cpp @@ -24,21 +24,23 @@ // disable warnings from gtest #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wundef" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" -#endif -#include +#endif // __clang__ +#include #include // for copy #include // for span #include // for array #include // for size_t -namespace{ -static const char *deathstring("Expected Death"); +namespace +{ + static constexpr char deathstring[] = "Expected Death"; } namespace gsl @@ -244,4 +246,4 @@ TEST(algorithm_tests, small_destination_span) #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__ diff --git a/tests/assertion_tests.cpp b/tests/assertion_tests.cpp index 0e4dd34..a42c209 100644 --- a/tests/assertion_tests.cpp +++ b/tests/assertion_tests.cpp @@ -24,12 +24,13 @@ //disable warnings from gtest #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wundef" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" -#endif +#endif // __clang__ #include #include // for fail_fast (ptr only), Ensures, Expects @@ -38,6 +39,8 @@ using namespace gsl; namespace { +static constexpr char deathstring[] = "Expected Death"; + int f(int i) { Expects(i > 0 && i < 10); @@ -50,8 +53,6 @@ int g(int i) Ensures(i > 0 && i < 10); return i; } - -static const char *deathstring("Expected Death"); } // namespace TEST(assertion_tests, expects) @@ -79,4 +80,4 @@ TEST(assertion_tests, ensures) #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__ diff --git a/tests/at_tests.cpp b/tests/at_tests.cpp index 98f261a..b43d06c 100644 --- a/tests/at_tests.cpp +++ b/tests/at_tests.cpp @@ -24,12 +24,13 @@ //disable warnings from gtest #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wundef" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" -#endif +#endif // __clang__ #include @@ -40,8 +41,9 @@ #include // for initializer_list #include // for vector -namespace{ -static const char *deathstring("Expected Death"); +namespace +{ + static constexpr char deathstring[] = "Expected Death"; } TEST(at_tests, static_array) @@ -152,4 +154,4 @@ static_assert(test_constexpr(), "FAIL"); #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__ diff --git a/tests/bounds_tests.cpp b/tests/bounds_tests.cpp index 5e73042..629e5d1 100644 --- a/tests/bounds_tests.cpp +++ b/tests/bounds_tests.cpp @@ -27,12 +27,13 @@ //disable warnings from gtest #pragma GCC diagnostic ignored "-Wundef" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" -#endif +#endif // __clang__ #include @@ -40,10 +41,6 @@ #include // for ptrdiff_t, size_t -namespace gsl { -struct fail_fast; -} // namespace gsl - using namespace std; using namespace gsl; @@ -127,4 +124,4 @@ copy(src_span_static, dst_span_static); #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__ diff --git a/tests/byte_tests.cpp b/tests/byte_tests.cpp index 36e10b0..bf22556 100644 --- a/tests/byte_tests.cpp +++ b/tests/byte_tests.cpp @@ -17,19 +17,20 @@ #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 +#pragma warning(disable : 26440 26426) +#endif // _MSC_VER #if __clang__ || __GNUC__ //disable warnings from gtest #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wundef" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" -#endif +#endif // __clang__ #include @@ -147,4 +148,4 @@ copy(src_span_static, dst_span_static); #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__ diff --git a/tests/multi_span_tests.cpp b/tests/multi_span_tests.cpp index a4fdc56..891bee3 100644 --- a/tests/multi_span_tests.cpp +++ b/tests/multi_span_tests.cpp @@ -28,13 +28,13 @@ //disable warnings from gtest #pragma GCC diagnostic ignored "-Wundef" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" - -#endif +#endif // __clang__ #include @@ -61,6 +61,7 @@ using namespace gsl; namespace { +static constexpr char deathstring[] = "Expected Death"; struct BaseClass { }; @@ -139,7 +140,6 @@ void fn(const Bounds&) static_assert(Bounds::static_size == 60, "static bounds is wrong size"); } -static const char *deathstring("Expected Death"); } // namespace TEST(multi_span_test, default_constructor) @@ -1886,4 +1886,4 @@ copy(src_span_static, dst_span_static); #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__ diff --git a/tests/notnull_tests.cpp b/tests/notnull_tests.cpp index b1ac4d4..47f5ac2 100644 --- a/tests/notnull_tests.cpp +++ b/tests/notnull_tests.cpp @@ -27,12 +27,13 @@ //disable warnings from gtest #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wundef" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" -#endif +#endif // __clang__ #include @@ -52,9 +53,9 @@ struct fail_fast; using namespace gsl; -namespace{ -static const char *deathstring("Expected Death"); -} +namespace +{ +static constexpr char deathstring[] = "Expected Death"; struct MyBase { @@ -148,7 +149,7 @@ GSL_SUPPRESS(f.4) // NO-FORMAT: attribute bool helper_const(not_null p) { return *p == 12; } int* return_pointer() { return nullptr; } -const int* return_pointer_const() { return nullptr; } +} //namespace TEST(notnull_tests, TestNotNullConstructors) { @@ -564,4 +565,4 @@ static_assert(std::is_nothrow_move_constructible>::value, #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__ diff --git a/tests/owner_tests.cpp b/tests/owner_tests.cpp index 2427803..6442033 100644 --- a/tests/owner_tests.cpp +++ b/tests/owner_tests.cpp @@ -25,12 +25,13 @@ //disable warnings from gtest #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wundef" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" -#endif +#endif // __clang__ #include @@ -62,4 +63,4 @@ TEST(owner_tests, check_pointer_constraint) #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__ diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index 9336812..f619d48 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -26,17 +26,19 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wundef" #pragma GCC diagnostic ignored "-Wunused-variable" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" -#endif +#endif // __clang__ + +#include #include // for byte #include // for narrow_cast, at #include // for span, span_iterator, operator==, operator!= -#include #include // for array #include // for ptrdiff_t @@ -58,6 +60,8 @@ using namespace gsl; namespace { +static constexpr char deathstring[] = "Expected Death"; + struct BaseClass { }; @@ -75,7 +79,6 @@ struct AddressOverloaded return {}; } }; -static const char *deathstring("Expected Death"); } // namespace TEST(span_test, constructors) @@ -1642,4 +1645,4 @@ TEST(span_test, from_array_constructor) #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__ diff --git a/tests/strict_notnull_tests.cpp b/tests/strict_notnull_tests.cpp index 766654b..a8d438a 100644 --- a/tests/strict_notnull_tests.cpp +++ b/tests/strict_notnull_tests.cpp @@ -27,12 +27,13 @@ //disable warnings from gtest #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wundef" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" -#endif +#endif // __clang__ #include #include // for not_null, operator<, operator<=, operator> @@ -143,7 +144,10 @@ TEST(strict_notnull_tests, TestStrictNotNull) } #if defined(__cplusplus) && (__cplusplus >= 201703L) -static const char *deathstring("Expected Death"); +namespace +{ +static constexpr char deathstring[] = "Expected Death"; +} TEST(strict_notnull_tests, TestStrictNotNullConstructorTypeDeduction) { @@ -211,4 +215,4 @@ static_assert(std::is_nothrow_move_constructible>::value, #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__ diff --git a/tests/strided_span_tests.cpp b/tests/strided_span_tests.cpp index f87f1dc..20f14ad 100644 --- a/tests/strided_span_tests.cpp +++ b/tests/strided_span_tests.cpp @@ -25,18 +25,17 @@ #if __clang__ || __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" - //disable warnings from gtest #pragma GCC diagnostic ignored "-Wundef" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" -#endif +#endif // __clang__ #include - #include // for byte #include // for narrow_cast #include // for strided_span, index, multi_span, strided_... @@ -47,16 +46,14 @@ #include // for integral_constant<>::value, is_convertible #include // for vector -namespace gsl { -struct fail_fast; -} // namespace gsl - using namespace std; using namespace gsl; + namespace { -static const char *deathstring("Expected Death"); +static constexpr char deathstring[] = "Expected Death"; + struct BaseClass { }; @@ -815,4 +812,4 @@ TEST(strided_span_tests, strided_span_conversion) #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__ diff --git a/tests/string_span_tests.cpp b/tests/string_span_tests.cpp index 16bcf07..b9cfdcc 100644 --- a/tests/string_span_tests.cpp +++ b/tests/string_span_tests.cpp @@ -25,12 +25,13 @@ //disable warnings from gtest #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wundef" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" -#endif +#endif // __clang__ #include @@ -49,6 +50,10 @@ using namespace std; using namespace gsl; +namespace +{ +static constexpr char deathstring[] = "Expected Death"; +} // Generic string functions namespace generic @@ -72,7 +77,6 @@ auto strnlen(const CharT* s, std::size_t n) namespace { -static const char *deathstring("Expected Death"); template T move_wrapper(T&& t) @@ -1233,4 +1237,4 @@ TEST(string_span_tests, as_writeable_bytes) #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__ diff --git a/tests/utils_tests.cpp b/tests/utils_tests.cpp index 5911371..d779384 100644 --- a/tests/utils_tests.cpp +++ b/tests/utils_tests.cpp @@ -25,12 +25,14 @@ //disable warnings from gtest #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wundef" -#endif +#endif // __clang__ || __GNUC__ + #if __clang__ #pragma GCC diagnostic ignored "-Wglobal-constructors" #pragma GCC diagnostic ignored "-Wused-but-marked-unused" #pragma GCC diagnostic ignored "-Wcovered-switch-default" -#endif +#endif // __clang__ + #include @@ -44,8 +46,9 @@ using namespace gsl; -namespace{ -static const char *deathstring("Expected Death"); +namespace +{ +static constexpr char deathstring[] = "Expected Death"; void f(int& i) { i += 1; } static int j = 0; void g() { j += 1; } @@ -153,4 +156,4 @@ TEST(utils_tests, narrow) #if __clang__ || __GNUC__ #pragma GCC diagnostic pop -#endif +#endif // __clang__ || __GNUC__