1*03514f19SPatrick WilliamsFrom 1b4d42ca2e97061042ec44a0b34ceb176c78c7e1 Mon Sep 17 00:00:00 2001 2*03514f19SPatrick WilliamsFrom: d-winsor <danwin@microsoft.com> 3*03514f19SPatrick WilliamsDate: Mon, 26 Feb 2024 13:17:12 -0800 4*03514f19SPatrick WilliamsSubject: [PATCH] Fix initialization in test (#1140) 5*03514f19SPatrick Williams 6*03514f19SPatrick Williams* Suppress unsafe-buffer-usage 7*03514f19SPatrick Williams 8*03514f19SPatrick WilliamsUpstream-Status: Backport [https://github.com/microsoft/GSL/commit/1b4d42ca2e97061042ec44a0b34ceb176c78c7e1] 9*03514f19SPatrick Williams 10*03514f19SPatrick WilliamsSigned-off-by: Peter Marko <peter.marko@siemens.com> 11*03514f19SPatrick Williams--- 12*03514f19SPatrick Williams include/gsl/span | 10 ++++++++++ 13*03514f19SPatrick Williams include/gsl/util | 10 ++++++++++ 14*03514f19SPatrick Williams tests/CMakeLists.txt | 10 ++++++++++ 15*03514f19SPatrick Williams tests/span_tests.cpp | 2 +- 16*03514f19SPatrick Williams 4 files changed, 31 insertions(+), 1 deletion(-) 17*03514f19SPatrick Williams 18*03514f19SPatrick Williamsdiff --git a/include/gsl/span b/include/gsl/span 19*03514f19SPatrick Williamsindex cc8a7b9..d254e4d 100644 20*03514f19SPatrick Williams--- a/include/gsl/span 21*03514f19SPatrick Williams+++ b/include/gsl/span 22*03514f19SPatrick Williams@@ -58,6 +58,12 @@ 23*03514f19SPatrick Williams #pragma GCC diagnostic ignored "-Wsign-conversion" 24*03514f19SPatrick Williams #endif 25*03514f19SPatrick Williams 26*03514f19SPatrick Williams+// Turn off clang unsafe buffer warnings as all accessed are guarded by runtime checks 27*03514f19SPatrick Williams+#if defined(__clang__) && __has_warning("-Wunsafe-buffer-usage") 28*03514f19SPatrick Williams+#pragma clang diagnostic push 29*03514f19SPatrick Williams+#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" 30*03514f19SPatrick Williams+#endif // defined(__clang__) && __has_warning("-Wunsafe-buffer-usage") 31*03514f19SPatrick Williams+ 32*03514f19SPatrick Williams namespace gsl 33*03514f19SPatrick Williams { 34*03514f19SPatrick Williams 35*03514f19SPatrick Williams@@ -818,4 +824,8 @@ as_writable_bytes(span<ElementType, Extent> s) noexcept 36*03514f19SPatrick Williams #pragma GCC diagnostic pop 37*03514f19SPatrick Williams #endif // __GNUC__ > 6 38*03514f19SPatrick Williams 39*03514f19SPatrick Williams+#if defined(__clang__) && __has_warning("-Wunsafe-buffer-usage") 40*03514f19SPatrick Williams+#pragma clang diagnostic pop 41*03514f19SPatrick Williams+#endif 42*03514f19SPatrick Williams+ 43*03514f19SPatrick Williams #endif // GSL_SPAN_H 44*03514f19SPatrick Williamsdiff --git a/include/gsl/util b/include/gsl/util 45*03514f19SPatrick Williamsindex a215bad..11735a8 100644 46*03514f19SPatrick Williams--- a/include/gsl/util 47*03514f19SPatrick Williams+++ b/include/gsl/util 48*03514f19SPatrick Williams@@ -39,6 +39,12 @@ 49*03514f19SPatrick Williams 50*03514f19SPatrick Williams #endif // _MSC_VER 51*03514f19SPatrick Williams 52*03514f19SPatrick Williams+// Turn off clang unsafe buffer warnings as all accessed are guarded by runtime checks 53*03514f19SPatrick Williams+#if defined(__clang__) && __has_warning("-Wunsafe-buffer-usage") 54*03514f19SPatrick Williams+#pragma clang diagnostic push 55*03514f19SPatrick Williams+#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" 56*03514f19SPatrick Williams+#endif // defined(__clang__) && __has_warning("-Wunsafe-buffer-usage") 57*03514f19SPatrick Williams+ 58*03514f19SPatrick Williams #if defined(__cplusplus) && (__cplusplus >= 201703L) 59*03514f19SPatrick Williams #define GSL_NODISCARD [[nodiscard]] 60*03514f19SPatrick Williams #else 61*03514f19SPatrick Williams@@ -157,4 +163,8 @@ constexpr auto at(std::span<T, extent> sp, const index i) -> decltype(sp[sp.size 62*03514f19SPatrick Williams 63*03514f19SPatrick Williams #endif // _MSC_VER 64*03514f19SPatrick Williams 65*03514f19SPatrick Williams+#if defined(__clang__) && __has_warning("-Wunsafe-buffer-usage") 66*03514f19SPatrick Williams+#pragma clang diagnostic pop 67*03514f19SPatrick Williams+#endif 68*03514f19SPatrick Williams+ 69*03514f19SPatrick Williams #endif // GSL_UTIL_H 70*03514f19SPatrick Williamsdiff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt 71*03514f19SPatrick Williamsindex cab4e56..20de9e1 100644 72*03514f19SPatrick Williams--- a/tests/CMakeLists.txt 73*03514f19SPatrick Williams+++ b/tests/CMakeLists.txt 74*03514f19SPatrick Williams@@ -167,6 +167,11 @@ else() 75*03514f19SPatrick Williams > 76*03514f19SPatrick Williams ) 77*03514f19SPatrick Williams endif(MSVC) 78*03514f19SPatrick Williams+check_cxx_compiler_flag("-Wno-unsafe-buffer-usage" WARN_UNSAFE_BUFFER) 79*03514f19SPatrick Williams+if (WARN_UNSAFE_BUFFER) 80*03514f19SPatrick Williams+ # This test uses very greedy heuristics such as "no pointer arithmetic on raw buffer" 81*03514f19SPatrick Williams+ target_compile_options(gsl_tests_config INTERFACE "-Wno-unsafe-buffer-usage") 82*03514f19SPatrick Williams+endif() 83*03514f19SPatrick Williams 84*03514f19SPatrick Williams # for tests to find the gtest header 85*03514f19SPatrick Williams target_include_directories(gsl_tests_config SYSTEM INTERFACE 86*03514f19SPatrick Williams@@ -267,6 +272,11 @@ else() 87*03514f19SPatrick Williams > 88*03514f19SPatrick Williams ) 89*03514f19SPatrick Williams endif(MSVC) 90*03514f19SPatrick Williams+check_cxx_compiler_flag("-Wno-unsafe-buffer-usage" WARN_UNSAFE_BUFFER) 91*03514f19SPatrick Williams+if (WARN_UNSAFE_BUFFER) 92*03514f19SPatrick Williams+ # This test uses very greedy heuristics such as "no pointer arithmetic on raw buffer" 93*03514f19SPatrick Williams+ target_compile_options(gsl_tests_config_noexcept INTERFACE "-Wno-unsafe-buffer-usage") 94*03514f19SPatrick Williams+endif() 95*03514f19SPatrick Williams 96*03514f19SPatrick Williams add_executable(gsl_noexcept_tests no_exception_ensure_tests.cpp) 97*03514f19SPatrick Williams target_link_libraries(gsl_noexcept_tests 98*03514f19SPatrick Williamsdiff --git a/tests/span_tests.cpp b/tests/span_tests.cpp 99*03514f19SPatrick Williamsindex 33ccf56..3c1dfe5 100644 100*03514f19SPatrick Williams--- a/tests/span_tests.cpp 101*03514f19SPatrick Williams+++ b/tests/span_tests.cpp 102*03514f19SPatrick Williams@@ -330,7 +330,7 @@ TEST(span_test, from_array_constructor) 103*03514f19SPatrick Williams EXPECT_TRUE(s.data() == std::addressof(arr2d[0])); 104*03514f19SPatrick Williams } 105*03514f19SPatrick Williams 106*03514f19SPatrick Williams- int arr3d[2][3][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; 107*03514f19SPatrick Williams+ int arr3d[2][3][2] = { { {1, 2}, {3, 4}, {5, 6} }, { {7, 8}, {9, 10}, {11, 12} } }; 108*03514f19SPatrick Williams 109*03514f19SPatrick Williams #ifdef CONFIRM_COMPILATION_ERRORS 110*03514f19SPatrick Williams { 111*03514f19SPatrick Williams-- 112*03514f19SPatrick Williams2.30.2 113*03514f19SPatrick Williams 114