From 2940006b5c653287a4261f3bc400f1b7b140e6a8 Mon Sep 17 00:00:00 2001 From: Dmitry Kobets <89153909+dmitrykobets-msft@users.noreply.github.com> Date: Mon, 11 Sep 2023 10:06:40 -0700 Subject: [PATCH] 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 https://github.com/llvm/llvm-project/issues/65689 that I've disabled inline. --- include/gsl/span | 7 +++++++ tests/CMakeLists.txt | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/gsl/span b/include/gsl/span index f61fd11..3f82a5e 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -777,8 +777,15 @@ span(const Container&) -> span; #endif // ( defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L) ) #if defined(GSL_USE_STATIC_CONSTEXPR_WORKAROUND) +#if defined(__clang__) && defined(_MSC_VER) && defined(__cplusplus) && (__cplusplus < 201703L) +#pragma clang diagnostic push +#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. +#endif // defined(__clang__) && defined(_MSC_VER) && defined(__cplusplus) && (__cplusplus < 201703L) template constexpr const typename span::size_type span::extent; +#if defined(__clang__) && defined(_MSC_VER) && defined(__cplusplus) && (__cplusplus < 201703L) +#pragma clang diagnostic pop +#endif // defined(__clang__) && defined(_MSC_VER) && defined(__cplusplus) && (__cplusplus < 201703L) #endif namespace details diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7a00fec..493285c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -121,7 +121,12 @@ if(MSVC) # MSVC or simulating MSVC ) check_cxx_compiler_flag("-Wno-reserved-identifier" WARN_RESERVED_ID) if (WARN_RESERVED_ID) - target_compile_options(gsl_tests_config INTERFACE "-Wno-reserved-identifier") + target_compile_options(gsl_tests_config INTERFACE "-Wno-reserved-identifier") + endif() + check_cxx_compiler_flag("-Wno-unsafe-buffer-usage" WARN_UNSAFE_BUFFER) + if (WARN_UNSAFE_BUFFER) + # This test uses very greedy heuristics such as "no pointer arithmetic on raw buffer" + target_compile_options(gsl_tests_config INTERFACE "-Wno-unsafe-buffer-usage") endif() else() target_compile_options(gsl_tests_config INTERFACE @@ -255,7 +260,12 @@ if(MSVC) # MSVC or simulating MSVC ) check_cxx_compiler_flag("-Wno-reserved-identifier" WARN_RESERVED_ID) if (WARN_RESERVED_ID) - target_compile_options(gsl_tests_config_noexcept INTERFACE "-Wno-reserved-identifier") + target_compile_options(gsl_tests_config_noexcept INTERFACE "-Wno-reserved-identifier") + endif() + check_cxx_compiler_flag("-Wno-unsafe-buffer-usage" WARN_UNSAFE_BUFFER) + if (WARN_UNSAFE_BUFFER) + # This test uses very greedy heuristics such as "no pointer arithmetic on raw buffer" + target_compile_options(gsl_tests_config_noexcept INTERFACE "-Wno-unsafe-buffer-usage") endif() else() target_compile_options(gsl_tests_config_noexcept INTERFACE