From 9810969c0fb2199997d9ebdcc46f75fcfd27de23 Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen <4643818-rmlarsen1@users.noreply.gitlab.com> Date: Sun, 22 Feb 2026 14:54:15 -0800 Subject: [PATCH] Suppress false-positive GCC and clang warnings in test builds libeigen/eigen!2187 Co-authored-by: Rasmus Munk Larsen --- CMakeLists.txt | 11 +++++++++++ test/CMakeLists.txt | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d5534fac..ca6914cc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -427,6 +427,17 @@ if (EIGEN_BUILD_TESTING) ei_add_cxx_compiler_flag("-fno-check-new") endif() + # GCC 12+ emits false-positive -Warray-bounds, -Wmaybe-uninitialized, + # -Wstringop-overread, and -Wnonnull warnings at -O2/-O3 in heavily + # templated code with mixed static/dynamic sizes. These are well-known + # compiler bugs (see GCC PR 109394, 106247, 105329, 98610, among others). + if (CMAKE_COMPILER_IS_GNUCXX) + ei_add_cxx_compiler_flag("-Wno-array-bounds") + ei_add_cxx_compiler_flag("-Wno-maybe-uninitialized") + ei_add_cxx_compiler_flag("-Wno-stringop-overread") + ei_add_cxx_compiler_flag("-Wno-nonnull") + endif() + if(ANDROID_NDK) ei_add_cxx_compiler_flag("-pie") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dc5f958f1..ef23acdc6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -336,6 +336,12 @@ else() set(EIGEN_FASTMATH_FLAGS "/fp:fast") endif() endif() +# The fastmath test intentionally uses NaN/infinity under -ffast-math. +# Suppress the clang warning about this being technically undefined. +check_cxx_compiler_flag("-Wno-nan-infinity-disabled" COMPILER_SUPPORT_WNO_NAN_INF) +if(COMPILER_SUPPORT_WNO_NAN_INF) + set(EIGEN_FASTMATH_FLAGS "${EIGEN_FASTMATH_FLAGS} -Wno-nan-infinity-disabled") +endif() ei_add_test(fastmath "${EIGEN_FASTMATH_FLAGS}")