From 3277f0559a1a0d3dc48e8b3a6385ce305f5cf6c3 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 17 Jun 2025 16:28:57 +0800 Subject: [PATCH] cmake: suppress -Wmaybe-uninitialized warning in memstore PageSet MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Suppress GCC-15 false positive warning about uninitialized memory in Page::operator delete() using placement new pattern. GCC-15 incorrectly warns about potentially uninitialized data when using placement new with manual memory management: ``` [409/506] Building CXX object src/os/CMakeFiles/os.dir/memstore/MemStore.cc.o In file included from /home/kefu/dev/ceph/src/os/memstore/MemStore.h:29, from /home/kefu/dev/ceph/src/os/memstore/MemStore.cc:28: In static member function ‘static void Page::operator delete(void*)’, inlined from ‘void Page::put()’ at /home/kefu/dev/ceph/src/os/memstore/PageSet.h:36:41: /home/kefu/dev/ceph/src/os/memstore/PageSet.h:83:42: warning: ‘*this.Page::data’ may be used uninitialized [-Wmaybe-uninitialized] 83 | delete[] reinterpret_cast(p)->data; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ ``` The warning is a false positive: Page instances are constructed using placement new over pre-allocated memory, requiring manual cleanup of the underlying data array. This is the intended behavior and memory is properly initialized. So, in this change we just silence this warning in CMake after checking its availability. Signed-off-by: Kefu Chai --- src/os/memstore/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/os/memstore/CMakeLists.txt b/src/os/memstore/CMakeLists.txt index 1f7db6b544d5d..e59b64af7b4fa 100644 --- a/src/os/memstore/CMakeLists.txt +++ b/src/os/memstore/CMakeLists.txt @@ -1,2 +1,10 @@ +include(CheckCXXCompilerFlag) + add_library(memstore MemStore.cc) +check_cxx_compiler_flag("-Wno-maybe-uninitialized" + HAS_WARNING_MAYBE_UNINITIALIZED) +if(HAS_WARNING_MAYBE_UNINITIALIZED) + target_compile_options(os + PRIVATE "-Wno-maybe-uninitialized") +endif() -- 2.39.5