PR c++/85285 - ICE with flexible array after substitution.
authorJason Merrill <jason@redhat.com>
Tue, 10 Apr 2018 14:23:54 +0000 (10:23 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 10 Apr 2018 14:23:54 +0000 (10:23 -0400)
* pt.c (instantiate_class_template_1): Check for flexible array in
union.

From-SVN: r259277

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/ext/flexary30.C [new file with mode: 0644]

index 33f0c37a3cde89827e4976e2b3e02ae8281752b7..43592502c6fc4081ac3611c54d49e5d0680564df 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-10  Jason Merrill  <jason@redhat.com>
+
+       PR c++/85285 - ICE with flexible array after substitution.
+       * pt.c (instantiate_class_template_1): Check for flexible array in
+       union.
+
 2018-04-09  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/85227
index db3d7e38d85329b58fc125d957e288e0eeeca426..76e546cdeaa7c47e0bda2453d2a86c45c2aaef10 100644 (file)
@@ -10904,6 +10904,14 @@ instantiate_class_template_1 (tree type)
                              cxx_incomplete_type_error (r, rtype);
                              TREE_TYPE (r) = error_mark_node;
                            }
+                         else if (TREE_CODE (rtype) == ARRAY_TYPE
+                                  && TYPE_DOMAIN (rtype) == NULL_TREE
+                                  && (TREE_CODE (type) == UNION_TYPE
+                                      || TREE_CODE (type) == QUAL_UNION_TYPE))
+                           {
+                             error ("flexible array member %qD in union", r);
+                             TREE_TYPE (r) = error_mark_node;
+                           }
                        }
 
                      /* If it is a TYPE_DECL for a class-scoped ENUMERAL_TYPE,
diff --git a/gcc/testsuite/g++.dg/ext/flexary30.C b/gcc/testsuite/g++.dg/ext/flexary30.C
new file mode 100644 (file)
index 0000000..59b7587
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/85285
+
+template<typename T> union A
+{
+  T x;                         // { dg-error "flexible array" }
+};
+
+A<int[]> a;