Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2940006

Browse files
Suppress some noisy / buggy warnings (#1136)
Two warnings were being emitted in the MSVC+LLVM tests. The warning `-Wunsafe-buffer-usage` is initially introduced in some capacity here https://reviews.llvm.org/D137346 pointing to documentation at https://discourse.llvm.org/t/rfc-c-buffer-hardening/65734. The warning is a stylistic checker whose goal is to "emit a warning every time an unsafe operation is performed on a raw pointer". This type of programming model is not useful for library implementations of types such as `span`, where direct manipulation of raw pointers is inevitable, so disable the warning altogether. There is also a false-positive warning llvm/llvm-project#65689 that I've disabled inline.
1 parent 9695da9 commit 2940006

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

include/gsl/span

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,15 @@ span(const Container&) -> span<Element>;
777777
#endif // ( defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L) )
778778

779779
#if defined(GSL_USE_STATIC_CONSTEXPR_WORKAROUND)
780+
#if defined(__clang__) && defined(_MSC_VER) && defined(__cplusplus) && (__cplusplus < 201703L)
781+
#pragma clang diagnostic push
782+
#pragma clang diagnostic ignored "-Wdeprecated" // Bug in clang-cl.exe which raises a C++17 -Wdeprecated warning about this static constexpr workaround in C++14 mode.
783+
#endif // defined(__clang__) && defined(_MSC_VER) && defined(__cplusplus) && (__cplusplus < 201703L)
780784
template <class ElementType, std::size_t Extent>
781785
constexpr const typename span<ElementType, Extent>::size_type span<ElementType, Extent>::extent;
786+
#if defined(__clang__) && defined(_MSC_VER) && defined(__cplusplus) && (__cplusplus < 201703L)
787+
#pragma clang diagnostic pop
788+
#endif // defined(__clang__) && defined(_MSC_VER) && defined(__cplusplus) && (__cplusplus < 201703L)
782789
#endif
783790

784791
namespace details

tests/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ if(MSVC) # MSVC or simulating MSVC
121121
)
122122
check_cxx_compiler_flag("-Wno-reserved-identifier" WARN_RESERVED_ID)
123123
if (WARN_RESERVED_ID)
124-
target_compile_options(gsl_tests_config INTERFACE "-Wno-reserved-identifier")
124+
target_compile_options(gsl_tests_config INTERFACE "-Wno-reserved-identifier")
125+
endif()
126+
check_cxx_compiler_flag("-Wno-unsafe-buffer-usage" WARN_UNSAFE_BUFFER)
127+
if (WARN_UNSAFE_BUFFER)
128+
# This test uses very greedy heuristics such as "no pointer arithmetic on raw buffer"
129+
target_compile_options(gsl_tests_config INTERFACE "-Wno-unsafe-buffer-usage")
125130
endif()
126131
else()
127132
target_compile_options(gsl_tests_config INTERFACE
@@ -255,7 +260,12 @@ if(MSVC) # MSVC or simulating MSVC
255260
)
256261
check_cxx_compiler_flag("-Wno-reserved-identifier" WARN_RESERVED_ID)
257262
if (WARN_RESERVED_ID)
258-
target_compile_options(gsl_tests_config_noexcept INTERFACE "-Wno-reserved-identifier")
263+
target_compile_options(gsl_tests_config_noexcept INTERFACE "-Wno-reserved-identifier")
264+
endif()
265+
check_cxx_compiler_flag("-Wno-unsafe-buffer-usage" WARN_UNSAFE_BUFFER)
266+
if (WARN_UNSAFE_BUFFER)
267+
# This test uses very greedy heuristics such as "no pointer arithmetic on raw buffer"
268+
target_compile_options(gsl_tests_config_noexcept INTERFACE "-Wno-unsafe-buffer-usage")
259269
endif()
260270
else()
261271
target_compile_options(gsl_tests_config_noexcept INTERFACE

0 commit comments

Comments
 (0)