emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strange test in stdalign.m4


From: Eli Zaretskii
Subject: Strange test in stdalign.m4
Date: Fri, 29 Mar 2013 17:57:21 +0300

The test program from m4/stdalign.m4, viz.:

  #include <stdalign.h>
  #include <stddef.h>

  /* Test that alignof yields a result consistent with offsetof.
     This catches GCC bug 52023
     <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>.  */
  #ifdef __cplusplus
   template <class t> struct alignof_helper { char a; t b; };
  # define ao(type) offsetof (alignof_helper<type>, b)
  #else
  # define ao(type) offsetof (struct { char a; type b; }, b)
  #endif
  char test_double[ao (double) % _Alignof (double) == 0 ? 1 : -1];
  char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1];
  char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1];

  /* Test _Alignas only on platforms where gnulib can help.  */
  #if (__GNUC__ || __IBMC__ || __IBMCPP__ || 0x5110 <= __SUNPRO_C || 1300 <= 
_MSC_VER)
  int alignas (8) alignas_int = 1;
  char test_alignas[_Alignof (alignas_int) == 8 ? 1 : -1];
  #endif

  int
  main ()
  {
    return 0;
  }

seems to always fail.  This line:

  char test_alignas[_Alignof (alignas_int) == 8 ? 1 : -1];

emits the following diagnostics:

  ta.c:36: error: expected specifier-qualifier-list before ‘alignas_int’
  ta.c:36: error: ‘struct <anonymous>’ has no member named ‘__b’

My understanding is that _Alignof accepts a data type as its argument,
whereas alignas_int is not a data type.  If I use typeof, like this:

  char test_alignas[_Alignof (typeof(alignas_int)) == 8 ? 1 : -1];

then the error is

  ta.c:36: error: size of array ‘test_alignas’ is negative

which means alignas didn't really work, right?

This fails the configure test of stdalign.h, even if I replace
stdalign.h with lib/stdalign.in.h, a gnulib replacement, which is
supposed to be correct.

I tried this with 2 different versions of GCC on 2 different systems,
with the same results.

What am I missing here?  Why does the test fail?

TIA




reply via email to

[Prev in Thread] Current Thread [Next in Thread]