libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 53d8ff41a2809b91b3e5d35b1fe0fecfbacaeb70
parent f6c159604efa9a7c6a79dd682924c1fb3368f4c3
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Wed, 27 Aug 2025 17:18:14 +0200

configure: check for constexpr support

Diffstat:
Mconfigure.ac | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/incl_priv/mhd_sys_options.h | 1+
Msrc/mhd2/Makefile.am | 2+-
Asrc/mhd2/mhd_constexpr.h | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 116 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac @@ -1383,6 +1383,56 @@ AS_IF([test "x$ac_cv_c_inline" != "xno" && test "x${mhd_cv_cc_kwd_forceinline}" SAVE_ac_c_werror_flag="$ac_c_werror_flag" ac_c_werror_flag="yes" +AC_CACHE_CHECK([whether 'constexpr' keywords supported by $CC],[mhd_cv_cc_kwd_constexpr], + [ + AC_LINK_IFELSE([ + AC_LANG_SOURCE([[ + +static constexpr int zero_const_expr_s = 0; +constexpr unsigned int one_const_expr_u = 1; + +enum some_Enm +{ + enm_Val_Zero = 0, + enm_Val_One = one_const_expr_u, + enm_Val_Two = 2 +}; + +int main(int argc, char *argv[]) +{ + enum some_Enm local_e_var; + static constexpr unsigned int arr0[1 + zero_const_expr_s] = { one_const_expr_u }; + constexpr int arr1[one_const_expr_u] = { zero_const_expr_s }; + + switch(argc) + { + case zero_const_expr_s: + local_e_var = enm_Val_One; + break; + case 1: + local_e_var = enm_Val_Zero; + break; + case 10: + local_e_var = enm_Val_Two; + break; + default: + local_e_var = enm_Val_Two; + break; + } + + return (arr0[0] + (unsigned int)local_e_var) == + one_const_expr_u ? (arr1[0] - zero_const_expr_s) : (!! argv[0]); +} + ]] + ) + ], + [mhd_cv_cc_kwd_constexpr="yes"],[mhd_cv_cc_kwd_constexpr="no"] + ) + ] +) +AS_VAR_IF([mhd_cv_cc_kwd_constexpr],["yes"], + [AC_DEFINE([MHD_HAVE_C_CONSTEXPR],[1],[Define to '1' if compiler supports "constexpr" keyword])] +) AC_CACHE_CHECK([for 'unreachable' keywords supported by $CC],[mhd_cv_cc_kwd_unreachable], [ mhd_cv_cc_kwd_unreachable="none" diff --git a/src/incl_priv/mhd_sys_options.h b/src/incl_priv/mhd_sys_options.h @@ -631,6 +631,7 @@ # define mhd_FALLTHROUGH ((void) 0) # undef _Atomic # define _Atomic /* empty */ +# undef MHD_HAVE_C_CONSTEXPR #endif /* Avoid interference with third-party headers */ diff --git a/src/mhd2/Makefile.am b/src/mhd2/Makefile.am @@ -35,7 +35,7 @@ libmicrohttpd2_la_SOURCES = \ compat_calloc.h \ sys_w32_ver.h \ mhd_align.h mhd_bithelpers.h mhd_byteorder.h \ - mhd_assert.h mhd_unreachable.h \ + mhd_constexpr.h mhd_assert.h mhd_unreachable.h \ mhd_cntnr_ptr.h mhd_arr_num_elems.h \ mhd_tristate.h mhd_status_code_int.h \ mhd_socket_type.h mhd_sockets_macros.h \ diff --git a/src/mhd2/mhd_constexpr.h b/src/mhd2/mhd_constexpr.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */ +/* + This file is part of GNU libmicrohttpd. + Copyright (C) 2025 Evgeny Grin (Karlson2k) + + GNU libmicrohttpd is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + GNU libmicrohttpd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + Alternatively, you can redistribute GNU libmicrohttpd and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version, together + with the eCos exception, as follows: + + As a special exception, if other files instantiate templates or + use macros or inline functions from this file, or you compile this + file and link it with other works to produce a work based on this + file, this file does not by itself cause the resulting work to be + covered by the GNU General Public License. However the source code + for this file must still be made available in accordance with + section (3) of the GNU General Public License v2. + + This exception does not invalidate any other reasons why a work + based on this file might be covered by the GNU General Public + License. + + You should have received copies of the GNU Lesser General Public + License and the GNU General Public License along with this library; + if not, see <https://www.gnu.org/licenses/>. +*/ + +/** + * @file src/mhd2/mhd_constexpr.h + * @brief The definition of the mhd_constexpr helper macro + * @author Karlson2k (Evgeny Grin) + */ + +#ifndef MHD_CONSTEXPR_H +#define MHD_CONSTEXPR_H 1 + +#include "mhd_sys_options.h" + +#ifdef MHD_HAVE_C_CONSTEXPR +/** + * Static compile-time constant. + * When used inside a function, must be placed before any code statements. + */ +# define mhd_constexpr static constexpr +#else +/** + * Static compile-time constant. + * When used inside a function, must be placed before any code statements. + */ +# define mhd_constexpr static const +#endif + +#endif /* ! MHD_CONSTEXPR_H */