]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/58664 ([c++11] ICE initializing array of incomplete type within union)
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 20 May 2014 13:30:40 +0000 (13:30 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 20 May 2014 13:30:40 +0000 (13:30 +0000)
/cp
2014-05-20  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/58664
* typeck2.c (cxx_incomplete_type_inform): New.
(cxx_incomplete_type_diagnostic): Use it.
* decl.c (grokdeclarator): Check the element type of an
incomplete array type; call the above.
* cp-tree.h (cxx_incomplete_type_inform): Declare.

/testsuite
2014-05-20  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/58664
* g++.dg/cpp0x/nsdmi-union6.C: New.
* g++.dg/parse/pr58664.C: Likewise.
* g++.dg/cpp0x/nsdmi6.C: Tweak.
* g++.dg/parse/crash31.C: Likewise.
* g++.dg/template/error2.C: Likewise.
* g++.dg/template/inherit8.C: Likewise.
* g++.dg/template/offsetof2.C: Likewise.

From-SVN: r210642

12 files changed:
gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/nsdmi-union6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/nsdmi6.C
gcc/testsuite/g++.dg/parse/crash31.C
gcc/testsuite/g++.dg/parse/pr58664.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/error2.C
gcc/testsuite/g++.dg/template/inherit8.C
gcc/testsuite/g++.dg/template/offsetof2.C

index 822f79be33c113f7e6980825adf22241299d1cc6..b15a9c97b02eefed1b163d012f3d0da3a6dd7246 100644 (file)
@@ -1,3 +1,12 @@
+2014-05-20  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/58664
+       * typeck2.c (cxx_incomplete_type_inform): New.
+       (cxx_incomplete_type_diagnostic): Use it.
+       * decl.c (grokdeclarator): Check the element type of an
+       incomplete array type; call the above.
+       * cp-tree.h (cxx_incomplete_type_inform): Declare.
+
 2014-05-19  Jason Merrill  <jason@redhat.com>
 
        PR c++/58761
index d13d71dcad9a1d7308a63130abedb5cf8d086c6b..32a8afbee6c7756cca9b481a9f84686971686894 100644 (file)
@@ -6158,6 +6158,7 @@ extern void cxx_incomplete_type_diagnostic        (const_tree, const_tree, diagnostic_t
 extern void cxx_incomplete_type_error          (const_tree, const_tree);
 #define cxx_incomplete_type_error(V,T) \
   (cxx_incomplete_type_diagnostic ((V), (T), DK_ERROR))
+extern void cxx_incomplete_type_inform                 (const_tree);
 extern tree error_not_base_type                        (tree, tree);
 extern tree binfo_or_else                      (tree, tree);
 extern void cxx_readonly_error                 (tree, enum lvalue_use);
index a29e3e3b2a06a407ed114f76c78bdcc66305f39f..81f127315ec8de687956f4066fbb9a31aa152b39 100644 (file)
@@ -10586,11 +10586,16 @@ grokdeclarator (const cp_declarator *declarator,
          }
        else if (!staticp && !dependent_type_p (type)
                 && !COMPLETE_TYPE_P (complete_type (type))
-                && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
+                && (TREE_CODE (type) != ARRAY_TYPE
+                    || !COMPLETE_TYPE_P (TREE_TYPE (type))
+                    || initialized == 0))
          {
            if (unqualified_id)
-             error ("field %qD has incomplete type %qT",
-                    unqualified_id, type);
+             {
+               error ("field %qD has incomplete type %qT",
+                      unqualified_id, type);
+               cxx_incomplete_type_inform (strip_array_types (type));
+             }
            else
              error ("name %qT has incomplete type", type);
 
index fb1546f91c8ee9fc880d38dd3b58d82d5345e85a..72995e9f2e6173a54236a0fa9d7ad3380b3b2bd3 100644 (file)
@@ -429,6 +429,25 @@ abstract_virtuals_error (abstract_class_use use, tree type)
   return abstract_virtuals_error_sfinae (use, type, tf_warning_or_error);
 }
 
+/* Print an inform about the declaration of the incomplete type TYPE.  */
+
+void
+cxx_incomplete_type_inform (const_tree type)
+{
+  location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type));
+  tree ptype = strip_top_quals (CONST_CAST_TREE (type));
+
+  if (current_class_type
+      && TYPE_BEING_DEFINED (current_class_type)
+      && same_type_p (ptype, current_class_type))
+    inform (loc, "definition of %q#T is not complete until "
+           "the closing brace", ptype);
+  else if (!TYPE_TEMPLATE_INFO (ptype))
+    inform (loc, "forward declaration of %q#T", ptype);
+  else
+    inform (loc, "declaration of %q#T", ptype);
+}
+
 /* Print an error message for invalid use of an incomplete type.
    VALUE is the expression that was used (or 0 if that isn't known)
    and TYPE is the type that was invalid.  DIAG_KIND indicates the
@@ -469,14 +488,7 @@ cxx_incomplete_type_diagnostic (const_tree value, const_tree type,
                                      "invalid use of incomplete type %q#T",
                                      type);
       if (complained)
-       {
-         if (!TYPE_TEMPLATE_INFO (type))
-           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
-                   "forward declaration of %q#T", type);
-         else
-           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
-                   "declaration of %q#T", type);
-       }
+       cxx_incomplete_type_inform (type);
       break;
 
     case VOID_TYPE:
index f4c9995544f6102c432ebdcc031901d1bdf0f545..95ceb3927cae19497106c6f7cfd158229ca2d6e5 100644 (file)
@@ -1,3 +1,14 @@
+2014-05-20  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/58664
+       * g++.dg/cpp0x/nsdmi-union6.C: New.
+       * g++.dg/parse/pr58664.C: Likewise.
+       * g++.dg/cpp0x/nsdmi6.C: Tweak.
+       * g++.dg/parse/crash31.C: Likewise.
+       * g++.dg/template/error2.C: Likewise.
+       * g++.dg/template/inherit8.C: Likewise.
+       * g++.dg/template/offsetof2.C: Likewise.
+
 2014-05-19  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * c-c++-common/gomp/simd4.c: Adjust for inform.
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-union6.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-union6.C
new file mode 100644 (file)
index 0000000..764fe21
--- /dev/null
@@ -0,0 +1,56 @@
+// PR c++/58664
+// { dg-do compile { target c++11 } }
+
+struct F;          // { dg-message "forward declaration" }
+
+union U            // { dg-message "not complete" }
+{
+  U u[1] = { 0 };  // { dg-error "incomplete type" }
+};
+
+template<typename T>
+union UT           // { dg-message "not complete" }
+{
+  UT u[1] = { 0 }; // { dg-error "incomplete type" }
+};
+
+template union UT<int>;
+
+union UF
+{
+  F u[1] = { 0 };  // { dg-error "incomplete type" }
+};
+
+template<typename T>
+union UFT
+{
+  F u[1] = { 0 };  // { dg-error "incomplete type" }
+};
+
+template union UFT<int>;
+
+struct S           // { dg-message "not complete" }
+{
+  S s[1] = { 0 };  // { dg-error "incomplete type" }
+};
+
+template<typename T>
+struct ST          // { dg-message "not complete" }
+{
+  ST s[1] = { 0 }; // { dg-error "incomplete type" }
+};
+
+template class ST<int>;
+
+struct SF
+{
+  F s[1] = { 0 };  // { dg-error "incomplete type" }
+};
+
+template<typename T>
+struct SFT
+{
+  F s[1] = { 0 };  // { dg-error "incomplete type" }
+};
+
+template class SFT<int>;
index e78f50019a5afbe54e4e49d9a66b749cad37c98a..f88a347426ad87347530058c12cd6686908e8191 100644 (file)
@@ -4,5 +4,5 @@
 struct A
 {
     typedef int int T; // { dg-error "two or more data types in declaration" }
-    struct T x[1] = { 0 }; // { dg-error "invalid|forward" }
+    struct T x[1] = { 0 }; // { dg-error "incomplete type|forward" }
 };
index c22ad5ed3ba09980959d5ac54a866ed4658379f4..e7d6bdc146599546c1e95ba1d0a3d8325f3c0853 100644 (file)
@@ -1,4 +1,4 @@
-struct A // { dg-message "forward declaration" }
+struct A // { dg-message "not complete" }
 {
   A : A; // { dg-error "expected|incomplete" }
   A : B; // { dg-error "not declared|incomplete" }
diff --git a/gcc/testsuite/g++.dg/parse/pr58664.C b/gcc/testsuite/g++.dg/parse/pr58664.C
new file mode 100644 (file)
index 0000000..489259a
--- /dev/null
@@ -0,0 +1,66 @@
+// PR c++/58664
+// { dg-do compile { target c++11 } }
+
+struct F;          // { dg-message "forward declaration" }
+
+union U            // { dg-message "not complete" }
+{
+  U u;             // { dg-error "field 'u' has incomplete type 'U'" }
+};
+
+union CU           // { dg-message "not complete" }
+{
+  const CU u;      // { dg-error "incomplete type" }
+};
+
+template<typename T>
+union UT           // { dg-message "not complete" }
+{
+  UT u;            // { dg-error "incomplete type" }
+};
+
+template union UT<int>;
+
+union UF
+{
+  F u;             // { dg-error "field 'u' has incomplete type 'F'" }
+};
+
+template<typename T>
+union UFT
+{
+  F u;             // { dg-error "incomplete type" }
+};
+
+template union UFT<int>;
+
+struct S           // { dg-message "not complete" }
+{
+  S s;             // { dg-error "field 's' has incomplete type 'S'" }
+};
+
+struct VS          // { dg-message "not complete" }
+{
+  volatile VS s;   // { dg-error "incomplete type" }
+};
+
+template<typename T>
+struct ST          // { dg-message "not complete" }
+{
+  ST s;            // { dg-error "incomplete type" }
+};
+
+template class ST<int>;
+
+struct SF
+{
+  F s;             // { dg-error "field 's' has incomplete type 'F'" }
+};
+
+template<typename T>
+struct SFT
+{
+  F s;             // { dg-error "incomplete type" }
+};
+
+template class SFT<int>;
index be5ab1d450ed02038c451f7f40f6a1d9a4197607..a7f199e51e42c2b45f2c8b7523513c8a389d1d5a 100644 (file)
@@ -7,8 +7,7 @@
 
 template<class T> struct X
 {
-  T m; // { dg-error "void" "void" }
-       // { dg-error "incomplete type" "incomplete" { target *-*-* } 10 }
+  T m; // { dg-error "incomplete type|invalid use" }
 };
 
 template<class T >
index f2ebd5cba6fecf323dcbdbb320cea21b04cb2bec..62a0f1da1a99932dd1bffea1ed84f4fbd1712865 100644 (file)
@@ -4,7 +4,7 @@ template <typename T>
 struct A
 {
   template <typename U>
-  struct B : public A <B<U> >  // { dg-message "declaration" }
+  struct B : public A <B<U> >  // { dg-message "not complete" }
   {
     struct C : public B<U>     // { dg-error "incomplete" }
     {
index 6f741a96205b5e122466aad8ed8597bfcc8168fe..3f08f9b0b8b0f59da60290cef3f18d30b12fa7f6 100644 (file)
@@ -1,7 +1,7 @@
 // PR c++/49085
 
 template <class T>
-struct A                       // { dg-message "declaration" }
+struct A                       // { dg-message "not complete" }
 {
   int i, j;
   int ar[__builtin_offsetof(A,j)]; // { dg-error "incomplete type" }