Hi,

I think the resolution of core/930 and C++11 itself are pretty clear: alignof of an array of unknown bound is fine, provided the element type is complete of course.

Tested x86_64-linux.

Thanks,
Paolo.

//////////////////////
/c-family
2011-12-29  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/51316
        * c-common.c (c_sizeof_or_alignof_type): In C++ allow for alignof
        of array types with an unknown bound.

/testsuite
2011-12-29  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/51316
        * g++.dg/cpp0x/alignof4.C: New.
Index: testsuite/g++.dg/cpp0x/alignof4.C
===================================================================
--- testsuite/g++.dg/cpp0x/alignof4.C   (revision 0)
+++ testsuite/g++.dg/cpp0x/alignof4.C   (revision 0)
@@ -0,0 +1,7 @@
+// PR c++/51316
+// { dg-options "-std=c++0x" }
+
+int main()
+{
+  alignof(int []);
+}
Index: c-family/c-common.c
===================================================================
--- c-family/c-common.c (revision 182710)
+++ c-family/c-common.c (working copy)
@@ -4382,13 +4382,22 @@ c_sizeof_or_alignof_type (location_t loc,
         return error_mark_node;
       value = size_one_node;
     }
-  else if (!COMPLETE_TYPE_P (type))
+  else if (!COMPLETE_TYPE_P (type)
+          && (!c_dialect_cxx () || is_sizeof || type_code != ARRAY_TYPE))
     {
       if (complain)
-       error_at (loc, "invalid application of %qs to incomplete type %qT ",
+       error_at (loc, "invalid application of %qs to incomplete type %qT",
                  op_name, type);
       return error_mark_node;
     }
+  else if (c_dialect_cxx () && type_code == ARRAY_TYPE
+          && !COMPLETE_TYPE_P (TREE_TYPE (type)))
+    {
+      if (complain)
+       error_at (loc, "invalid application of %qs to array type %qT of "
+                 "incomplete element type", op_name, type);
+      return error_mark_node;
+    }
   else
     {
       if (is_sizeof)

Reply via email to