re PR c++/8227 (g++ 3.3: ctors not called in static array initialization)
authorMark Mitchell <mark@codesourcery.com>
Sun, 1 Dec 2002 04:55:20 +0000 (04:55 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Sun, 1 Dec 2002 04:55:20 +0000 (04:55 +0000)
PR c++/8227
* decl.c (layout_var_decl): Deal gracefully with erroneous types.
(check_initializer): Validate the type of the initialized
variable, even if the initializer is absent.
* typeck.c (cp_type_quals): Deal gracefully with erroneous types.

PR c++/8227
* g++.dg/template/ctor2.C: New test.

From-SVN: r59672

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/pt.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/ctor2.C [new file with mode: 0644]

index 87cfabee95d313c72bce6bb2ca32ea797fa4f672..aee593f470d4ee7f21485e900712bdec107a9569 100644 (file)
@@ -1,11 +1,15 @@
 2002-11-30  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/8227
+       * decl.c (layout_var_decl): Deal gracefully with erroneous types.
+       (check_initializer): Validate the type of the initialized
+       variable, even if the initializer is absent.
+       * typeck.c (cp_type_quals): Deal gracefully with erroneous types.
+       
        PR c++/8214
        * typeck.c (convert_for_assignment): Do not use
        decl_constant_value on the operand.
 
-2002-11-30  Mark Mitchell  <mark@codesourcery.com>
-
        PR c++/8511
        * pt.c (instantiate_decl): Handle template friends defined outside
        of the class correctly.
index 5a30e5b5ef322f24f9d7b958f665b9108dd1d232..dbb96eb6a28039334d0428d1ca3c3ea3fb2fcc91 100644 (file)
@@ -7631,6 +7631,7 @@ layout_var_decl (decl)
   if (!DECL_EXTERNAL (decl))
     complete_type (type);
   if (!DECL_SIZE (decl) 
+      && TREE_TYPE (decl) != error_mark_node
       && (COMPLETE_TYPE_P (type)
          || (TREE_CODE (type) == ARRAY_TYPE 
              && !TYPE_DOMAIN (type)
@@ -7974,33 +7975,30 @@ check_initializer (tree decl, tree init, int flags)
      the static initialization -- if any -- of DECL.  */
   DECL_INITIAL (decl) = NULL_TREE;
 
-  /* Check the initializer.  */
-  if (init)
-    {
-      /* Things that are going to be initialized need to have complete
-        type.  */
-      TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
+  /* Things that are going to be initialized need to have complete
+     type.  */
+  TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
 
-      if (type == error_mark_node)
-       /* We will have already complained.  */
-       init = NULL_TREE;
-      else if (COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
-       {
-         error ("variable-sized object `%D' may not be initialized", decl);
-         init = NULL_TREE;
-       }
-      else if (TREE_CODE (type) == ARRAY_TYPE
-              && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
-       {
-         error ("elements of array `%#D' have incomplete type", decl);
-         init = NULL_TREE;
-       }
-      else if (TREE_CODE (type) != ARRAY_TYPE && !COMPLETE_TYPE_P (type))
-       {
-         error ("`%D' has incomplete type", decl);
-         TREE_TYPE (decl) = error_mark_node;
-         init = NULL_TREE;
-       }
+  if (type == error_mark_node)
+    /* We will have already complained.  */
+    init = NULL_TREE;
+  else if (init && COMPLETE_TYPE_P (type) 
+          && !TREE_CONSTANT (TYPE_SIZE (type)))
+    {
+      error ("variable-sized object `%D' may not be initialized", decl);
+      init = NULL_TREE;
+    }
+  else if (TREE_CODE (type) == ARRAY_TYPE
+          && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
+    {
+      error ("elements of array `%#D' have incomplete type", decl);
+      init = NULL_TREE;
+    }
+  else if (TREE_CODE (type) != ARRAY_TYPE && !COMPLETE_TYPE_P (type))
+    {
+      error ("`%D' has incomplete type", decl);
+      TREE_TYPE (decl) = error_mark_node;
+      init = NULL_TREE;
     }
 
   if (TREE_CODE (decl) == CONST_DECL)
index 99f10d57dfcf549be549391d8293f996735bc887..77b2fd95056bf1e21a2ce64b6e0b7e5440140e67 100644 (file)
@@ -10063,7 +10063,7 @@ instantiate_decl (d, defer_ok)
 
   code_pattern = DECL_TEMPLATE_RESULT (td);
 
-  /* In the case of a friend temlpate whose definition is provided
+  /* In the case of a friend template whose definition is provided
      outside the class, we may have too many arguments.  Drop the ones
      we don't need.  */
   args = get_innermost_template_args (gen_args,
index 6a0ec18f0c16aa6e886ab0226750882d1f220589..85eef41c2e0e8799daf0430c28af603a6d8ba099 100644 (file)
@@ -6473,6 +6473,8 @@ cp_type_quals (type)
      tree type;
 {
   type = strip_array_types (type);
+  if (type == error_mark_node)
+    return TYPE_UNQUALIFIED;
   return TYPE_QUALS (type);
 }
 
index 1ac64f5847b83836c4b24c65ddbb41d0c3303979..5574e17a54966c94c43308c5467eb312c9ef9c10 100644 (file)
@@ -1,10 +1,11 @@
 2002-11-30  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/8227
+       * g++.dg/template/ctor2.C: New test.
+
        PR c++/8214
        * g++.dg/init/string1.C: New test.
 
-2002-11-30  Mark Mitchell  <mark@codesourcery.com>
-
        PR c++/8511
        * g++.dg/template/friend8.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/template/ctor2.C b/gcc/testsuite/g++.dg/template/ctor2.C
new file mode 100644 (file)
index 0000000..1c8d8a6
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do run }
+
+int i;
+
+template <class T>
+struct S
+{
+  S () { i = 1; }
+};
+
+static S<int> s[1];
+
+int main ()
+{
+  if (!i)
+    return 1;
+}
+