diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2017-03-09 15:18:59 -0500 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2017-03-28 21:59:23 -0400 |
commit | 4cb824699e12c39fad97fb3d9085ced0d14c067c (patch) | |
tree | 9a835d8efb7739e6436d3fc24b4b5a290b95df7d /config/c-compiler.m4 | |
parent | 66b764341ba12206f01e2600713bdc3abdb070b3 (diff) | |
download | postgresql-4cb824699e12c39fad97fb3d9085ced0d14c067c.tar.gz |
Cast result of copyObject() to correct type
copyObject() is declared to return void *, which allows easily assigning
the result independent of the input, but it loses all type checking.
If the compiler supports typeof or something similar, cast the result to
the input type. This creates a greater amount of type safety. In some
cases, where the result is assigned to a generic type such as Node * or
Expr *, new casts are now necessary, but in general casts are now
unnecessary in the normal case and indicate that something unusual is
happening.
Reviewed-by: Mark Dilger <hornschnorter@gmail.com>
Diffstat (limited to 'config/c-compiler.m4')
-rw-r--r-- | config/c-compiler.m4 | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4 index 3321f226f3..b366e40cff 100644 --- a/config/c-compiler.m4 +++ b/config/c-compiler.m4 @@ -178,6 +178,33 @@ fi])# PGAC_C_STATIC_ASSERT +# PGAC_C_TYPEOF +# ------------- +# Check if the C compiler understands typeof or a variant. Define +# HAVE_TYPEOF if so, and define 'typeof' to the actual key word. +# +AC_DEFUN([PGAC_C_TYPEOF], +[AC_CACHE_CHECK(for typeof, pgac_cv_c_typeof, +[pgac_cv_c_typeof=no +for pgac_kw in typeof __typeof__ decltype; do + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], +[int x = 0; +$pgac_kw(x) y; +y = x; +return y;])], +[pgac_cv_c_typeof=$pgac_kw]) + test "$pgac_cv_c_typeof" != no && break +done]) +if test "$pgac_cv_c_typeof" != no; then + AC_DEFINE(HAVE_TYPEOF, 1, + [Define to 1 if your compiler understands `typeof' or something similar.]) + if test "$pgac_cv_c_typeof" != typeof; then + AC_DEFINE(typeof, $pgac_cv_c_typeof, [Define to how the compiler spells `typeof'.]) + fi +fi])# PGAC_C_TYPEOF + + + # PGAC_C_TYPES_COMPATIBLE # ----------------------- # Check if the C compiler understands __builtin_types_compatible_p, |