re PR c++/51316 (alignof doesn't work with arrays of unknown bound)
authorPaolo Carlini <paolo.carlini@oracle.com>
Fri, 30 Dec 2011 21:11:20 +0000 (21:11 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 30 Dec 2011 21:11:20 +0000 (21:11 +0000)
/c-family
2011-12-30  Paolo Carlini  <paolo.carlini@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-30  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/51316
* g++.dg/cpp0x/alignof4.C: New.

From-SVN: r182746

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/alignof4.C [new file with mode: 0644]

index b076e7602f3764ae24b7880434a89e2ab17a51ce..7850829108ae1920a4638c5958eff860465f7efd 100644 (file)
@@ -1,3 +1,9 @@
+2011-12-30  Paolo Carlini  <paolo.carlini@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.
+
 2011-12-20  Joseph Myers  <joseph@codesourcery.com>
 
        * c-common.c (flag_isoc99): Update comment to refer to C11.
index 6f88760c9476bc7ed55b8eb271b16c3312bf5d44..013c71a6420f01969aa8753973daabcdd11d2ea1 100644 (file)
@@ -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)
index c49c10012c3db28e5c5c4905ef3fa883ac0a4ea6..34662342a8f127dbc19515e05ae719e82f74c78a 100644 (file)
@@ -1,3 +1,8 @@
+2011-12-30  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51316
+       * g++.dg/cpp0x/alignof4.C: New.
+
 2011-12-29  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        PR testsuite/51702
diff --git a/gcc/testsuite/g++.dg/cpp0x/alignof4.C b/gcc/testsuite/g++.dg/cpp0x/alignof4.C
new file mode 100644 (file)
index 0000000..92d636f
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/51316
+// { dg-options "-std=c++0x" }
+
+int main()
+{
+  alignof(int []);
+}