From e299436c490f00b2c252290f9b5ea08c83e3997d Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sat, 1 Feb 2025 17:30:36 -0800 Subject: [PATCH 1/2] [libc] Build with -Wdeprecated, fix some warnings While GCC's -Wdeprecated is on by default and doesn't do much, Clang's -Wdeprecated enables many more things. More apply in C++20, so switch a test file that tickled one to using that. In future, C++20 should probably be made the baseline for compiling all the libc code. --- libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 3 ++- libc/src/__support/CPP/span.h | 2 ++ libc/test/src/setjmp/CMakeLists.txt | 2 ++ libc/test/src/setjmp/setjmp_test.cpp | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake index 12420db331961..0facb0b9be0c1 100644 --- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake +++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake @@ -179,8 +179,9 @@ function(_get_common_compile_options output_var flags) endif() list(APPEND compile_options "-Wconversion") list(APPEND compile_options "-Wno-sign-conversion") - # Silence this warning because _Complex is a part of C99. + list(APPEND compile_options "-Wdeprecated") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # Silence this warning because _Complex is a part of C99. list(APPEND compile_options "-fext-numeric-literals") else() list(APPEND compile_options "-Wno-c99-extensions") diff --git a/libc/src/__support/CPP/span.h b/libc/src/__support/CPP/span.h index e9e3dbf169ce0..e5073bd3c9d87 100644 --- a/libc/src/__support/CPP/span.h +++ b/libc/src/__support/CPP/span.h @@ -52,6 +52,8 @@ template class span { LIBC_INLINE constexpr span() : span_data(nullptr), span_size(0) {} + LIBC_INLINE constexpr span(const span&) = default; + LIBC_INLINE constexpr span(pointer first, size_type count) : span_data(first), span_size(count) {} diff --git a/libc/test/src/setjmp/CMakeLists.txt b/libc/test/src/setjmp/CMakeLists.txt index 049df89ba39a6..392230784bd99 100644 --- a/libc/test/src/setjmp/CMakeLists.txt +++ b/libc/test/src/setjmp/CMakeLists.txt @@ -11,6 +11,8 @@ add_libc_unittest( libc_setjmp_unittests SRCS setjmp_test.cpp + CXX_STANDARD + 20 DEPENDS libc.src.setjmp.longjmp libc.src.setjmp.setjmp diff --git a/libc/test/src/setjmp/setjmp_test.cpp b/libc/test/src/setjmp/setjmp_test.cpp index 9e5f74a1734b3..27113cd6e0631 100644 --- a/libc/test/src/setjmp/setjmp_test.cpp +++ b/libc/test/src/setjmp/setjmp_test.cpp @@ -27,7 +27,7 @@ TEST(LlvmLibcSetJmpTest, SetAndJumpBack) { // The first time setjmp is called, it should return 0. // Subsequent calls will return the value passed to jump_back below. if (LIBC_NAMESPACE::setjmp(buf) <= MAX_LOOP) { - ++n; + n = n + 1; jump_back(buf, n); } ASSERT_EQ(longjmp_called, n); From 7ef574fee9bf984748528ac36431fc65c79ffbf3 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sat, 1 Feb 2025 17:47:28 -0800 Subject: [PATCH 2/2] clang-format --- libc/src/__support/CPP/span.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/src/__support/CPP/span.h b/libc/src/__support/CPP/span.h index e5073bd3c9d87..a41c9b744e370 100644 --- a/libc/src/__support/CPP/span.h +++ b/libc/src/__support/CPP/span.h @@ -10,7 +10,7 @@ #include // For size_t -#include "array.h" // For array +#include "array.h" // For array #include "src/__support/macros/config.h" #include "type_traits.h" // For remove_cv_t, enable_if_t, is_same_v, is_const_v @@ -52,7 +52,7 @@ template class span { LIBC_INLINE constexpr span() : span_data(nullptr), span_size(0) {} - LIBC_INLINE constexpr span(const span&) = default; + LIBC_INLINE constexpr span(const span &) = default; LIBC_INLINE constexpr span(pointer first, size_type count) : span_data(first), span_size(count) {}