allow to pass unnamed structs even in C++.
(AC_CHECK_SIZEOF): Likewise.
Also fix quoting error in `AC_MSG_FAILURE' arguments.
* tests/semantics.at (AC_CHECK_ALIGNOF struct, AC_CHECK_SIZEOF
struct): New tests for unnamed structs, each both native and
cross-compiling.
2006-03-11 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+ * lib/autoconf/types.m4 (_AC_CHECK_TYPE_NEW): Use a typedef to
+ allow to pass unnamed structs even in C++.
+ (AC_CHECK_SIZEOF): Likewise.
+ Also fix quoting error in `AC_MSG_FAILURE' arguments.
+ * tests/semantics.at (AC_CHECK_ALIGNOF struct, AC_CHECK_SIZEOF
+ struct): New tests for unnamed structs, each both native and
+ cross-compiling.
+
* lib/autoconf/c.m4 (AC_C_TYPEOF): Use typedef to avoid defining
a structure inside a cast, for C++ conformance.
* lib/autoconf/types.m4 (AC_CHECK_ALIGNOF): Likewise.
# (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.
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])],
-[if (($1 *) 0)
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])
+typedef $1 ac__type_new_;],
+[if ((ac__type_new_ *) 0)
return 0;
-if (sizeof ($1))
+if (sizeof (ac__type_new_))
return 0;])],
[AS_VAR_SET(ac_Type, yes)],
[AS_VAR_SET(ac_Type, no)])])
# 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_COMPUTE_INT([(long int) (sizeof ($1))],
+ _AC_COMPUTE_INT([(long int) (sizeof (ac__type_sizeof_))],
[AS_TR_SH([ac_cv_sizeof_$1])],
- [AC_INCLUDES_DEFAULT([$3])],
- [AC_MSG_FAILURE([cannot compute sizeof ($1), 77])])
+ [AC_INCLUDES_DEFAULT([$3])
+ typedef $1 ac__type_sizeof_;],
+ [AC_MSG_FAILURE([cannot compute sizeof ($1)], 77)])
else
AS_TR_SH([ac_cv_sizeof_$1])=0
fi])dnl
])])
+# AC_CHECK_ALIGNOF struct
+# -----------------------
+# Not cross-compiling.
+AT_CHECK_MACRO([AC_CHECK_ALIGNOF struct],
+[[AC_CHECK_ALIGNOF([struct { char c; }])
+AC_CHECK_ALIGNOF([struct nosuchstruct])
+]],
+[AT_CHECK([[grep "#define ALIGNOF_STRUCT___CHAR_C___ [^0]" config.h]],
+ 0, ignore)
+AT_CHECK([[grep "#define ALIGNOF_STRUCT_NOSUCHSTRUCT 0" config.h]],
+ 0, ignore)
+])
+
+
+# AC_CHECK_ALIGNOF struct
+# -----------------------
+AT_CHECK_MACRO([AC_CHECK_ALIGNOF struct],
+[[# Exercise the code used when cross-compiling
+cross_compiling=yes
+AC_CHECK_ALIGNOF([struct { char c; }])
+AC_CHECK_ALIGNOF([struct nosuchstruct])
+]],
+[AT_CHECK([[grep "#define ALIGNOF_STRUCT___CHAR_C___ [^0]" config.h]],
+ 0, ignore)
+AT_CHECK([[grep "#define ALIGNOF_STRUCT_NOSUCHSTRUCT 0" config.h]],
+ 0, ignore)
+])
+
+
# AC_CHECK_SIZEOF
# ---------------
# Not cross-compiling.
])])
+# AC_CHECK_SIZEOF structs
+# -----------------------
+# Not cross-compiling.
+AT_CHECK_MACRO([AC_CHECK_SIZEOF struct],
+[[AC_C_CONST
+AC_CHECK_SIZEOF([struct { char c; int x; }])
+AC_CHECK_SIZEOF([const struct { const char *p; int x; }])
+AC_CHECK_SIZEOF([struct nosuchstruct])
+]],
+[AT_CHECK([[grep "#define SIZEOF_STRUCT___CHAR_C__INT_X___ [^0]" config.h]],
+ 0, ignore)
+AT_CHECK([[grep "#define SIZEOF_CONST_STRUCT___CONST_CHAR_PP__INT_X___ [^0]" config.h]],
+ 0, ignore)
+AT_CHECK([[grep "#define SIZEOF_STRUCT_NOSUCHSTRUCT 0" config.h]],
+ 0, ignore)
+])
+
+
+# AC_CHECK_SIZEOF
+# ---------------
+AT_CHECK_MACRO([AC_CHECK_SIZEOF struct],
+[[# Exercise the code used when cross-compiling
+cross_compiling=yes
+AC_C_CONST
+AC_CHECK_SIZEOF([struct { char c; int x; }])
+AC_CHECK_SIZEOF([const struct { const char *p; int x; }])
+AC_CHECK_SIZEOF([struct nosuchstruct])
+]],
+[AT_CHECK([[grep "#define SIZEOF_STRUCT___CHAR_C__INT_X___ [^0]" config.h]],
+ 0, ignore)
+AT_CHECK([[grep "#define SIZEOF_CONST_STRUCT___CONST_CHAR_PP__INT_X___ [^0]" config.h]],
+ 0, ignore)
+AT_CHECK([[grep "#define SIZEOF_STRUCT_NOSUCHSTRUCT 0" config.h]],
+ 0, ignore)
+])
+
+
# AC_CHECK_TYPES
# --------------
# Check that it performs the correct actions.