OSDN Git Service

* c-typeck.c (digest_init): Issue error messages about
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 25 May 2001 06:34:16 +0000 (06:34 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 25 May 2001 06:34:16 +0000 (06:34 +0000)
invalid constants, not warnings.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@42560 138bc75d-0d04-0410-961f-82ee72b054a4

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

index f464a4a..c2c6e29 100644 (file)
@@ -1,5 +1,10 @@
 2001-05-24  Mark Mitchell  <mark@codesourcery.com>
 
+       * c-typeck.c (digest_init): Issue error messages about 
+       invalid constants, not warnings.
+
+2001-05-24  Mark Mitchell  <mark@codesourcery.com>
+
        * invoke.texi (-fno-builtin): Document that this is always on
        in C++.
 
index 3cbf6c6..71dae28 100644 (file)
@@ -4791,14 +4791,21 @@ digest_init (type, init, require_constant, constructor_constant)
          if (flag_pedantic_errors)
            inside_init = error_mark_node;
        }
-      else if (require_constant && ! TREE_CONSTANT (inside_init))
+      else if (require_constant 
+              && (!TREE_CONSTANT (inside_init)
+                  /* This test catches things like `7 / 0' which
+                     result in an expression for which TREE_CONSTANT
+                     is true, but which is not actually something
+                     that is a legal constant.  We really should not
+                     be using this function, because it is a part of
+                     the back-end.  Instead, the expression should
+                     already have been turned into ERROR_MARK_NODE.  */
+                  || !initializer_constant_valid_p (inside_init,
+                                                    TREE_TYPE (inside_init))))
        {
          error_init ("initializer element is not constant");
          inside_init = error_mark_node;
        }
-      else if (require_constant
-              && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
-       pedwarn ("initializer element is not computable at load time");
 
       return inside_init;
     }
diff --git a/gcc/testsuite/gcc.dg/noncompile/20010524-1.c b/gcc/testsuite/gcc.dg/noncompile/20010524-1.c
new file mode 100644 (file)
index 0000000..754a38c
--- /dev/null
@@ -0,0 +1,2 @@
+int i = 7 / 0; /* { dg-error "not constant" } */
+