1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-19 17:02:53 +03:00

Refactor static_assert() support.

HAVE__STATIC_ASSERT was really a test for GCC statement expressions,
as needed for StaticAssertExpr() now that _Static_assert could be
assumed to be available through our C11 requirement.  This
artificially prevented Visual Studio from being able to use
static_assert() in other contexts.

Instead, make a new test for HAVE_STATEMENT_EXPRESSIONS, and use that
to control only whether StaticAssertExpr() uses fallback code, not the
other variants.  This improves the quality of failure messages in the
(much more common) other variants under Visual Studio.

Also get rid of the two separate implementations for C++, since the C
implementation is also also valid as C++11.  While it is a stretch to
apply HAVE_STATEMENT_EXPRESSIONS tested with $CC to a C++ compiler,
the previous C++ coding assumed that the C++ compiler had them
unconditionally, so it isn't a new stretch.  In practice, the C and
C++ compilers are very likely to agree, and if a combination is ever
reported that falsifies this assumption we can always reconsider that.

Author: Thomas Munro <thomas.munro@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CA%2BhUKGKvr0x_oGmQTUkx%3DODgSksT2EtgCA6LmGx_jQFG%3DsDUpg%40mail.gmail.com
This commit is contained in:
Peter Eisentraut
2025-12-15 11:43:11 +01:00
parent 366dcdaf57
commit 17f446784d
6 changed files with 40 additions and 69 deletions

18
configure vendored
View File

@@ -14846,9 +14846,9 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for _Static_assert" >&5
$as_echo_n "checking for _Static_assert... " >&6; }
if ${pgac_cv__static_assert+:} false; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for statement expressions" >&5
$as_echo_n "checking for statement expressions... " >&6; }
if ${pgac_cv_statement_expressions+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -14863,18 +14863,18 @@ main ()
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
pgac_cv__static_assert=yes
pgac_cv_statement_expressions=yes
else
pgac_cv__static_assert=no
pgac_cv_statement_expressions=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__static_assert" >&5
$as_echo "$pgac_cv__static_assert" >&6; }
if test x"$pgac_cv__static_assert" = xyes ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_statement_expressions" >&5
$as_echo "$pgac_cv_statement_expressions" >&6; }
if test x"$pgac_cv_statement_expressions" = xyes ; then
$as_echo "#define HAVE__STATIC_ASSERT 1" >>confdefs.h
$as_echo "#define HAVE_STATEMENT_EXPRESSIONS 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for typeof" >&5