From 784c32457122491d189681bf9e0468eb42bfa599 Mon Sep 17 00:00:00 2001
From: Alexandre Janniaux <ajanni@videolabs.io>
Date: Wed, 18 May 2022 11:15:32 +0200
Subject: [PATCH] configure: check typeof on C++ compilers

C compilers can have GNU extensions to support typeof in C code, but
some C++ compilers like clang are removing the builtin since decltype
can be used in C++ without the constraints from typeof. Decltype is not
100% equivalent for this reason: references will be kept in the returned
type.

The check in m4/typeof.m4 comes from graydon/monotone and dovecot/core
and was slightly modified to namespace the define for C++ code.
---
 configure.ac |  3 +++
 m4/typeof.m4 | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 m4/typeof.m4

diff --git a/configure.ac b/configure.ac
index 2d798212b838..cc2451570bf6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -68,7 +68,10 @@ dnl Check for compiler properties
 AC_C_CONST
 AC_C_INLINE
 AC_C_RESTRICT
+AC_LANG_PUSH([C++])
 AX_CXX_COMPILE_STDCXX_14([noext], [mandatory])
+AX_CXX_TYPEOF
+AC_LANG_POP([C++])
 
 dnl Extend the --help string at the current spot.
 AC_DEFUN([EXTEND_HELP_STRING], [m4_divert_once([HELP_ENABLE], [$1])])
diff --git a/m4/typeof.m4 b/m4/typeof.m4
new file mode 100644
index 000000000000..e234dcdd3707
--- /dev/null
+++ b/m4/typeof.m4
@@ -0,0 +1,20 @@
+dnl @synopsis AX_CXX_TYPEOF
+dnl
+dnl tests for the presence of the gcc hashmap stl extension
+dnl
+dnl @author Patrick Mauritz <oxygene@studentenbude.ath.cx>
+dnl @version 2005-08-15
+dnl @license AllPermissive
+
+AC_DEFUN([AX_CXX_TYPEOF],[
+AC_LANG_ASSERT([C++])
+AC_CACHE_CHECK(whether the C++ compiler supports typeof,
+ac_cv_cxx_typeof,
+[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ int x; typeof (x) y[6]; ]])],
+  [ac_cv_cxx_typeof=yes],
+  [ac_cv_cxx_typeof=no])
+])
+if test "$ac_cv_cxx_typeof" = yes; then
+  AC_DEFINE(HAVE_CXX_TYPEOF, 1, [Define if the compiler supports typeof.])
+fi 
+])
-- 
GitLab