c-typeck.c (output_init_element): Call digest_init just once...
authorJakub Jelinek <jakub@redhat.com>
Wed, 5 Dec 2001 14:14:01 +0000 (15:14 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 5 Dec 2001 14:14:01 +0000 (15:14 +0100)
* c-typeck.c (output_init_element): Call digest_init
just once, not in each if branch and check its return value for
error_mark_node.

* gcc.dg/noncompile/20011025-1.c: New test.

From-SVN: r47673

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/noncompile/20011025-1.c [new file with mode: 0644]

index 95e2075e3f81078fb44536623ea0f4f4573e6a3b..e2485c52f2247b25f93a1d33853c8acd698673a6 100644 (file)
@@ -1,3 +1,9 @@
+2001-12-05  Jakub Jelinek  <jakub@redhat.com>
+
+       * c-typeck.c (output_init_element): Call digest_init
+       just once, not in each if branch and check its return value for
+       error_mark_node.
+
 2001-12-05  Jakub Jelinek  <jakub@redhat.com>
 
        * c-decl.c (pushdecl): Only increase n_incomplete if pushed decl's
index 297afad8ce8881b63668b5fb98ebeeeeac9d37f9..56775049a1ca2d1c9647093cd7e13d150655d18b 100644 (file)
@@ -4701,7 +4701,7 @@ digest_init (type, init, require_constant, constructor_constant)
 
   if (type == error_mark_node
       || init == error_mark_node
-      || TREE_TYPE (init)  == error_mark_node)
+      || TREE_TYPE (init) == error_mark_node)
     return error_mark_node;
 
   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
@@ -6267,6 +6267,8 @@ output_init_element (value, type, field, pending)
                  || TREE_CHAIN (field)))))
     return;
 
+  value = digest_init (type, value, require_constant_value,
+                      require_constant_elements);
   if (value == error_mark_node)
     {
       constructor_erroneous = 1;
@@ -6283,9 +6285,7 @@ output_init_element (value, type, field, pending)
          && tree_int_cst_lt (field, constructor_unfilled_index))
        set_nonincremental_init ();
 
-      add_pending_init (field,
-                       digest_init (type, value, require_constant_value, 
-                                    require_constant_elements));
+      add_pending_init (field, value);
       return;
     }
   else if (TREE_CODE (constructor_type) == RECORD_TYPE
@@ -6311,9 +6311,7 @@ output_init_element (value, type, field, pending)
            }
        }
 
-      add_pending_init (field,
-                       digest_init (type, value, require_constant_value, 
-                                    require_constant_elements));
+      add_pending_init (field, value);
       return;
     }
   else if (TREE_CODE (constructor_type) == UNION_TYPE
@@ -6332,10 +6330,7 @@ output_init_element (value, type, field, pending)
   if (field && TREE_CODE (field) == INTEGER_CST)
     field = copy_node (field);
   constructor_elements
-    = tree_cons (field, digest_init (type, value,
-                                    require_constant_value, 
-                                    require_constant_elements),
-                constructor_elements);
+    = tree_cons (field, value, constructor_elements);
 
   /* Advance the variable that indicates sequential elements output.  */
   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
index c300901c5d9dbcf8c75d4093dbad39f328fddb7f..56b2f089d40c19a5ce6034fa2eea41b801bd3f72 100644 (file)
@@ -2,6 +2,8 @@
 
        * gcc.c-torture/compile/20011130-1.c: New test.
 
+       * gcc.dg/noncompile/20011025-1.c: New test.
+
 2001-12-04  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * gcc.c-torture/execute/20000722-1.x,
diff --git a/gcc/testsuite/gcc.dg/noncompile/20011025-1.c b/gcc/testsuite/gcc.dg/noncompile/20011025-1.c
new file mode 100644 (file)
index 0000000..51e60e5
--- /dev/null
@@ -0,0 +1,5 @@
+double foo [] =
+{ &bar,                /* { dg-error "undeclared|is not constant|near init" } */
+  (void *) 0 };        /* { dg-error "incompatible types|is not constant|near init" } */
+double baz [] =
+{ (void *) 0 };        /* { dg-error "incompatible types|is not constant|near init" } */