From df06966f1f0ba67fb063546aaa1f2c2b123d2f44 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Mon, 5 Oct 2026 21:02:24 +0300
Subject: [PATCH 88/88] 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 a29820a79c..5e00062c18 100644
--- a/configure.ac
+++ b/configure.ac
@@ -702,7 +702,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 704fa72844..339657bec3 100644
--- a/meson.build
+++ b/meson.build
@@ -51,7 +51,8 @@ c_cpp_args = [
 cpp_args = [
   '-Wno-deprecated-declarations',
   '-fPIC',
-  '-Wtrailing-whitespace'
+  '-Wtrailing-whitespace',
+  '-Wno-c++20-extensions'
   ]
 
 foreach arg : c_args
@@ -1091,14 +1092,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

