From ad8b801c7e9c2da4b6f056ec87bf5e5ed522b418 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Mon, 5 Oct 2026 21:02:24 +0300
Subject: [PATCH 41/41] Fix configure check for 'C++20 capture this' on clang

Both meson and autotools based builds affected.

See RM #2335

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 configure.ac |  2 +-
 m4/debug.m4  |  3 ++-
 meson.build  | 18 +++++++++++++-----
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4e62eb4b47..d6a8ab746e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -673,7 +673,7 @@ dnl Detect flags to be used in configure tests that should fail on warnings
 WERROR_C_TEST_FLAGS=""
 WERROR_CXX_TEST_FLAGS=""
 FC_C_FLAGS([-Werror -Wall], [], [WERROR_C_TEST_FLAGS])
-FC_CXX_FLAGS([-Werror -Wall], [], [WERROR_CXX_TEST_FLAGS])
+FC_CXX_FLAGS([-Werror -Wall -Wno-c++20-extensions], [], [WERROR_CXX_TEST_FLAGS])
 
 FC_C99_VARIADIC_MACROS
 FC_C99_VARIABLE_ARRAYS
diff --git a/m4/debug.m4 b/m4/debug.m4
index dcf680e39e..0206dbfbbf 100644
--- a/m4/debug.m4
+++ b/m4/debug.m4
@@ -76,7 +76,8 @@ dnl -Wall set earlier, and not the other way around.
 FC_C_FLAGS([-Wno-tautological-compare],
            [], [EXTRA_DEBUG_CFLAGS])
 if test "x$cxx_works" = "xyes" ; then
-  FC_CXX_FLAGS([-Wno-tautological-compare -Wno-deprecated-declarations],
+  FC_CXX_FLAGS([-Wno-tautological-compare -Wno-deprecated-declarations \
+                -Wno-c++20-extensions],
                [], [EXTRA_DEBUG_CXXFLAGS])
 fi
 
diff --git a/meson.build b/meson.build
index 0ef4ac17f3..9ab5082262 100644
--- a/meson.build
+++ b/meson.build
@@ -51,7 +51,8 @@ c_cpp_args = [
 
 cpp_args = [
   '-Wno-deprecated-declarations',
-  '-fPIC'
+  '-fPIC',
+  '-Wno-c++20-extensions'
   ]
 
 foreach arg : c_args
@@ -1065,14 +1066,21 @@ if svgflags
   pub_conf_data.set('FREECIV_SVG_FLAGS', 1)
 endif
 
-if cxx_build and cxx_compiler.compiles('''
+if cxx_build
+  if cxx_compiler.has_argument('-Wno-c++20-extensions')
+    accept_cxx_20 = ['-Wno-c++20-extensions']
+  else
+    accept_cxx_20 = []
+  endif
+  if cxx_compiler.compiles('''
 class me {
 void top(); };
 void me::top() { (void) [=, this]() { this->top(); }; };
 ''',
-     name: 'C++20 capture this',
-     args: ['-Werror', '-Wall'])
-  pub_conf_data.set('FREECIV_HAVE_CXX20_CAPTURE_THIS', 1)
+       name: 'C++20 capture this',
+       args: ['-Werror', '-Wall', accept_cxx_20])
+    pub_conf_data.set('FREECIV_HAVE_CXX20_CAPTURE_THIS', 1)
+  endif
 endif
 
 if not meson.is_cross_build()
-- 
2.53.0

