+2007-04-11 Paul Eggert <eggert@cs.ucla.edu>
+
+ * doc/autoconf.texi (Generic Types): Document the restrictions
+ on types imposed by AC_CHECK_TYPE, AC_CHECK_TYPES.
+ (Generic Compiler Characteristics): AC_CHECK_SIZEOF now works
+ with objects too. Document the restrictions on its use.
+ Document the restrictions on AC_CHECK_ALIGNOF's type argument.
+ * lib/autoconf/types.m4 (_AC_CHECK_TYPE_NEW):
+ For C, just try sizeof (TYPE) and sizeof ((TYPE)); if the former
+ works but the latter doesn't, then it's a valid type.
+ This lets people use function types and so forth.
+ For C++ there doesn't seem to be a simple solution, so leave it alone.
+ (AC_CHECK_SIZEOF): Allow argument to be a variable.
+ (AC_CHECK_SIZEOF, AC_CHECK_ALIGNOF): Don't bother to invoke
+ AC_CHECK_TYPE; that wasn't documented or necessary.
+
2007-04-11 Stepan Kasal <kasal@ucw.cz>
* lib/autoconf/general.m4 (_AC_LINK_IFELSE): Skip AS_TEST_X
@acindex{CHECK_TYPE}
Check whether @var{type} is defined. It may be a compiler builtin type
or defined by the @var{includes} (@pxref{Default Includes}).
+
+In C, @var{type} must be a type-id, so that the expression @samp{sizeof
+(@var{type})} is valid (but @samp{sizeof ((@var{type}))} is not). The
+rules in C++ are currently more complicated and restrictive: @var{type}
+must be a string of tokens such that @samp{typedef @var{type} foo;} is a
+valid type definition. However, the C++ approach has problems (for
+example, it mishandles function types) and may change in future versions
+of Autoconf.
@end defmac
@defmac AC_CHECK_TYPES (@var{types}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
@acindex{CHECK_TYPES}
For each @var{type} of the @var{types} that is defined, define
-@code{HAVE_@var{type}} (in all capitals). If no @var{includes} are
+@code{HAVE_@var{type}} (in all capitals). Each @var{type} must follow
+the rules of @code{AC_CHECK_TYPE}. If no @var{includes} are
specified, the default includes are used (@pxref{Default Includes}). If
@var{action-if-found} is given, it is additional shell code to execute
when one of the types is found. If @var{action-if-not-found} is given,
@node Generic Compiler Characteristics
@subsection Generic Compiler Characteristics
-@defmac AC_CHECK_SIZEOF (@var{type}, @ovar{unused}, @dvar{includes, default-includes})
+@defmac AC_CHECK_SIZEOF (@var{type-or-expr}, @ovar{unused}, @dvar{includes, default-includes})
@acindex{CHECK_SIZEOF}
-Define @code{SIZEOF_@var{type}} (@pxref{Standard Symbols}) to be the
-size in bytes of @var{type}. If @samp{type} is unknown, it gets a size
-of 0. If no @var{includes} are specified, the default includes are used
+Define @code{SIZEOF_@var{type-or-expr}} (@pxref{Standard Symbols}) to be
+the size in bytes of @var{type-or-expr}, which may be either a type or
+an expression returning a value that has a size. If the expression
+@samp{sizeof (@var{type-or-expr})} is invalid, the result is 0. If no
+@var{includes} are specified, the default includes are used
(@pxref{Default Includes}).
This macro now works even when cross-compiling. The @var{unused}
@defmac AC_CHECK_ALIGNOF (@var{type}, @dvar{includes, default-includes})
@acindex{CHECK_ALIGNOF}
Define @code{ALIGNOF_@var{type}} (@pxref{Standard Symbols}) to be the
-alignment in bytes of @var{type}. If @samp{type} is unknown, it gets a size
-of 0. If no @var{includes} are specified, the default includes are used
+alignment in bytes of @var{type}. @samp{@var{type} x;} must be valid as
+a structure member declaration. If @samp{type} is unknown, the result
+is 0. If no @var{includes} are specified, the default includes are used
(@pxref{Default Includes}).
@end defmac
# But this succeeds if TYPE is a variable: you get the size of the
# variable's type!!!
#
-# This time you tell yourself the last two options *together* will make
-# it. And indeed this is the solution invented by Alexandre Oliva.
+# So, to filter out the last possibility, you try this too:
+#
+# sizeof ((TYPE));
+#
+# This fails if TYPE is a type, but succeeds if TYPE is actually a variable.
#
# Also note that we use
#
# to `read' sizeof (to avoid warnings), while not depending on its type
# (not necessarily size_t etc.). Equally, instead of defining an unused
# variable, we just use a cast to avoid warnings from the compiler.
-# Suggested by Paul Eggert.
#
# Now, the next issue is that C++ disallows defining types inside casts
# and inside `sizeof()', but we would like to allow unnamed structs, for
-# use inside AC_CHECK_SIZEOF, for example. So we create a typedef of the
-# new type. Note that this does not obviate the need for the other
-# constructs in general.
+# use inside AC_CHECK_SIZEOF, for example. So for C++ we create a typedef
+# of the new type. Note that this breaks for some types, e.g., function
+# types, but we don't know C++ well enough to fix this.
m4_define([_AC_CHECK_TYPE_NEW],
[AS_VAR_PUSHDEF([ac_Type], [ac_cv_type_$1])dnl
AC_CACHE_CHECK([for $1], [ac_Type],
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])
-typedef $1 ac__type_new_;],
-[if ((ac__type_new_ *) 0)
+[AS_VAR_SET([ac_Type], [no])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])
+#ifdef __cplusplus
+typedef $1 ac__type_new_;
+#endif
+],
+[#ifdef __cplusplus
+if ((ac__type_new_ *) 0)
return 0;
if (sizeof (ac__type_new_))
- return 0;])],
- [AS_VAR_SET([ac_Type], [yes])],
- [AS_VAR_SET([ac_Type], [no])])])
+ return 0;
+#else
+if (sizeof ($1))
+ return 0;
+#endif
+])],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
+ [if (sizeof (($1)))
+ return 0;])],
+ [],
+ [AS_VAR_SET([ac_Type], [yes])])])])
AS_IF([test AS_VAR_GET([ac_Type]) = yes], [$2], [$3])[]dnl
AS_VAR_POPDEF([ac_Type])dnl
])# _AC_CHECK_TYPE_NEW
AC_DEFUN([AC_CHECK_SIZEOF],
[AS_LITERAL_IF([$1], [],
[AC_FATAL([$0: requires literal arguments])])dnl
-AC_CHECK_TYPE([$1], [], [], [$3])
# The cast to long int works around a bug in the HP C Compiler
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
# This bug is HP SR number 8606223364.
_AC_CACHE_CHECK_INT([size of $1], [AS_TR_SH([ac_cv_sizeof_$1])],
- [(long int) (sizeof (ac__type_sizeof_))],
- [AC_INCLUDES_DEFAULT([$3])
- typedef $1 ac__type_sizeof_;],
+ [(long int) (sizeof ($1))],
+ [AC_INCLUDES_DEFAULT([$3])],
[if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
AC_MSG_FAILURE([cannot compute sizeof ($1)], 77)
else
AC_DEFUN([AC_CHECK_ALIGNOF],
[AS_LITERAL_IF([$1], [],
[AC_FATAL([$0: requires literal arguments])])dnl
-AC_CHECK_TYPE([$1], [], [], [$2])
# The cast to long int works around a bug in the HP C Compiler,
# see AC_CHECK_SIZEOF for more information.
_AC_CACHE_CHECK_INT([alignment of $1], [AS_TR_SH([ac_cv_alignof_$1])],