This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch to make __alignof__ error on incomplete types


Here's the patch to make __alignof__ on incomplete types error, as was discussed
earlier this week, plus a doc bit.  No copyright assignment on file yet, hopefully
this tiny change won't need it.  (There should be a test case too, but I
don't have
dejagnu running on OS X yet, sorry.)

The form of the code is from c_sizeof.  I note a couple refs to
__alignof in nearby
code, and it is accepted as a keyword in addition to __alignof__, but
the manual
mentions only the longer form; seems like either the code refs and error message
should change, or else the manual.

Stan


2000-03-09  Stan Shebs  <shebs@apple.com>

        * c-typeck.c (c_alignof): Error on incomplete types.
        * extend.texi (Alignment): Document this.


Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-typeck.c,v
retrieving revision 1.55
diff -c -3 -p -r1.55 c-typeck.c
*** c-typeck.c  2000/03/07 11:41:15     1.55
--- c-typeck.c  2000/03/09 21:56:52
*************** c_alignof (type)
*** 781,786 ****
--- 781,792 ----
    if (code == VOID_TYPE || code == ERROR_MARK)
      return size_one_node;
  
+   if (TYPE_SIZE (type) == 0)
+     {
+       error ("__alignof__ applied to an incomplete type");
+       return size_zero_node;
+     }
+ 
    return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
  }
  

Index: extend.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/extend.texi,v
retrieving revision 1.43
diff -c -3 -p -r1.43 extend.texi
*** extend.texi 2000/02/29 01:42:52     1.43
--- extend.texi 2000/03/09 21:56:54
*************** the value of @code{__alignof__ (foo1.y)}
*** 1879,1884 ****
--- 1879,1886 ----
  @code{__alignof__ (int)}, even though the data type of @code{foo1.y}
  does not itself demand any alignment.@refill
  
+ It is an error to ask for the alignment of an incomplete type.
+ 
  A related feature which lets you specify the alignment of an object is
  @code{__attribute__ ((aligned (@var{alignment})))}; see the following
  section.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]