unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Strange test in stdalign.m4
@ 2013-03-29 14:57 Eli Zaretskii
  2013-03-29 16:53 ` Paul Eggert
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2013-03-29 14:57 UTC (permalink / raw)
  To: Paul Eggert; +Cc: emacs-devel

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




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-03-30 17:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-29 14:57 Strange test in stdalign.m4 Eli Zaretskii
2013-03-29 16:53 ` Paul Eggert
2013-03-29 17:25   ` Eli Zaretskii
2013-03-30  2:42     ` Paul Eggert
2013-03-30  5:58       ` Eli Zaretskii
2013-03-30 17:32         ` Paul Eggert
2013-03-30 17:40           ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).