summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-09-30 14:38:31 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-09-30 14:38:31 -0400
commitea473fb2dee7dfe61f8fbdfac9d9da87d84e564e (patch)
treef54d9cb4b0200c7e81d07b942fbf384855db8297 /config
parent26fd82ddf1273d5df20b892fc02c8ca756d2e2bc (diff)
downloadpostgresql-ea473fb2dee7dfe61f8fbdfac9d9da87d84e564e.tar.gz
Add infrastructure for compile-time assertions about variable types.
Currently, the macros only work with fairly recent gcc versions, but there is room to expand them to other compilers that have comparable features. Heavily revised and autoconfiscated version of a patch by Andres Freund.
Diffstat (limited to 'config')
-rw-r--r--config/c-compiler.m440
1 files changed, 40 insertions, 0 deletions
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index 9398ca6c47..069b468daa 100644
--- a/config/c-compiler.m4
+++ b/config/c-compiler.m4
@@ -121,6 +121,46 @@ fi])# PGAC_C_FUNCNAME_SUPPORT
+# PGAC_C_STATIC_ASSERT
+# -----------------------
+# Check if the C compiler understands _Static_assert(),
+# and define HAVE__STATIC_ASSERT if so.
+#
+# We actually check the syntax ({ _Static_assert(...) }), because we need
+# gcc-style compound expressions to be able to wrap the thing into macros.
+AC_DEFUN([PGAC_C_STATIC_ASSERT],
+[AC_CACHE_CHECK(for _Static_assert, pgac_cv__static_assert,
+[AC_TRY_LINK([],
+[({ _Static_assert(1, "foo"); })],
+[pgac_cv__static_assert=yes],
+[pgac_cv__static_assert=no])])
+if test x"$pgac_cv__static_assert" = xyes ; then
+AC_DEFINE(HAVE__STATIC_ASSERT, 1,
+ [Define to 1 if your compiler understands _Static_assert.])
+fi])# PGAC_C_STATIC_ASSERT
+
+
+
+# PGAC_C_TYPES_COMPATIBLE
+# -----------------------
+# Check if the C compiler understands __builtin_types_compatible_p,
+# and define HAVE__BUILTIN_TYPES_COMPATIBLE_P if so.
+#
+# We check usage with __typeof__, though it's unlikely any compiler would
+# have the former and not the latter.
+AC_DEFUN([PGAC_C_TYPES_COMPATIBLE],
+[AC_CACHE_CHECK(for __builtin_types_compatible_p, pgac_cv__types_compatible,
+[AC_TRY_COMPILE([],
+[ int x; static int y[__builtin_types_compatible_p(__typeof__(x), int)]; ],
+[pgac_cv__types_compatible=yes],
+[pgac_cv__types_compatible=no])])
+if test x"$pgac_cv__types_compatible" = xyes ; then
+AC_DEFINE(HAVE__BUILTIN_TYPES_COMPATIBLE_P, 1,
+ [Define to 1 if your compiler understands __builtin_types_compatible_p.])
+fi])# PGAC_C_TYPES_COMPATIBLE
+
+
+
# PGAC_PROG_CC_CFLAGS_OPT
# -----------------------
# Given a string, check if the compiler supports the string as a