re PR c++/27961 (ICE on invalid template declaration)
authorLee Millward <lee.millward@codesourcery.com>
Thu, 12 Oct 2006 20:02:53 +0000 (20:02 +0000)
committerLee Millward <lmillward@gcc.gnu.org>
Thu, 12 Oct 2006 20:02:53 +0000 (20:02 +0000)
       PR c++/27961
       * decl.c (start_decl): Return error_mark_node if a
       function is initialized like a variable.
       (check_var_type): If a variable of field is declared void,
       set the type to error_mark_node.
       (grokdeclarator): Check the return type of check_var_type.
       * class.c (finish_struct_1): Robustify.

       * g++.dg/template/crash60.C: New test.
       * g++.dg/other/large-size-array.C: Adjust error markers.
       * g++.dg/parse/crash27.C: Likewise.
       * g++.dg/template/crash1.C: Likewise.

From-SVN: r117671

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/large-size-array.C
gcc/testsuite/g++.dg/parse/crash27.C
gcc/testsuite/g++.dg/template/crash1.C

index 1ac313b..4102503 100644 (file)
@@ -1,3 +1,13 @@
+2006-10-12 Lee Millward <lee.millward@codesourcery.com>
+
+       PR c++/27961
+       * decl.c (start_decl): Return error_mark_node if a
+       function is initialized like a variable.
+       (check_var_type): If a variable of field is declared void,
+       set the type to error_mark_node.
+       (grokdeclarator): Check the return type of check_var_type.
+       * class.c (finish_struct_1): Robustify.
+       
 2006-10-11  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/29175
index fa11606..e4bf89e 100644 (file)
@@ -5062,6 +5062,7 @@ finish_struct_1 (tree t)
      working on.  */
   for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x))
     if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
+        && TREE_TYPE (x) != error_mark_node
        && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (x)), t))
       DECL_MODE (x) = TYPE_MODE (t);
 
index e95870d..e814c0a 100644 (file)
@@ -3854,8 +3854,7 @@ start_decl (const cp_declarator *declarator,
 
       case FUNCTION_DECL:
        error ("function %q#D is initialized like a variable", decl);
-       initialized = 0;
-       break;
+       return error_mark_node;
 
       default:
        break;
@@ -6810,7 +6809,7 @@ check_var_type (tree identifier, tree type)
        }
       else
        error ("variable or field declared void");
-      type = integer_type_node;
+      type = error_mark_node;
     }
 
   return type;
@@ -8178,7 +8177,11 @@ grokdeclarator (const cp_declarator *declarator,
   /* We don't check parameter types here because we can emit a better
      error message later.  */
   if (decl_context != PARM)
-    type = check_var_type (unqualified_id, type);
+    {
+      type = check_var_type (unqualified_id, type);
+      if (type == error_mark_node)
+        return error_mark_node;
+    }
 
   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
index b13454e..ce07d43 100644 (file)
@@ -1,3 +1,11 @@
+2006-10-12 Lee Millward <lee.millward@codesourcery.com>
+
+       PR c++/27961
+       * g++.dg/template/crash60.C: New test.
+       * g++.dg/other/large-size-array.C: Adjust error markers.
+       * g++.dg/parse/crash27.C: Likewise.
+       * g++.dg/template/crash1.C: Likewise.
+       
 2006-10-12  Steve Ellcey  <sje@cup.hp.com>
 
        PR testsuite/29093
index 900c503..1385878 100644 (file)
@@ -17,7 +17,7 @@ int
 main (void)
 {
   int a[DIM][DIM];  /* { dg-error "size of array 'a' is too large" } */
-  return sub (&a[0][0]);
+  return sub (&a[0][0]);  /* { dg-error "declared" } */
 }
 
 
index 4d65177..1a13f81 100644 (file)
@@ -6,4 +6,3 @@ void Dispatcher()
        /* { dg-error "expected type" "expected 1" { target *-*-* } 4 } */
        /* { dg-error "expected `,' before" "expected 2" { target *-*-* } 4 } */
        /* { dg-error "expected `\\\)" "expected 3" { target *-*-* } 4 } */
-       /* { dg-error "expected ',' or" "expected 4" { target *-*-* } 4 } */
index 16d584e..a500da1 100644 (file)
@@ -13,5 +13,5 @@ class S
 
 template <class I>
 void S::Foo(int (*f)(TYPO&o) ) // { dg-error "Foo|f|TYPO|o" }
-{ // { dg-error "expected `;'" }
+{ 
 }