Commit 650fcd07 by Lee Millward Committed by Lee Millward

re PR c++/27961 (ICE on invalid template declaration)

       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
parent dc0aeb60
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> 2006-10-11 Mark Mitchell <mark@codesourcery.com>
PR c++/29175 PR c++/29175
......
...@@ -5062,6 +5062,7 @@ finish_struct_1 (tree t) ...@@ -5062,6 +5062,7 @@ finish_struct_1 (tree t)
working on. */ working on. */
for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x)) for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x))
if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (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)) && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (x)), t))
DECL_MODE (x) = TYPE_MODE (t); DECL_MODE (x) = TYPE_MODE (t);
......
...@@ -3854,8 +3854,7 @@ start_decl (const cp_declarator *declarator, ...@@ -3854,8 +3854,7 @@ start_decl (const cp_declarator *declarator,
case FUNCTION_DECL: case FUNCTION_DECL:
error ("function %q#D is initialized like a variable", decl); error ("function %q#D is initialized like a variable", decl);
initialized = 0; return error_mark_node;
break;
default: default:
break; break;
...@@ -6810,7 +6809,7 @@ check_var_type (tree identifier, tree type) ...@@ -6810,7 +6809,7 @@ check_var_type (tree identifier, tree type)
} }
else else
error ("variable or field declared void"); error ("variable or field declared void");
type = integer_type_node; type = error_mark_node;
} }
return type; return type;
...@@ -8178,7 +8177,11 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -8178,7 +8177,11 @@ grokdeclarator (const cp_declarator *declarator,
/* We don't check parameter types here because we can emit a better /* We don't check parameter types here because we can emit a better
error message later. */ error message later. */
if (decl_context != PARM) 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 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
......
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> 2006-10-12 Steve Ellcey <sje@cup.hp.com>
PR testsuite/29093 PR testsuite/29093
...@@ -17,7 +17,7 @@ int ...@@ -17,7 +17,7 @@ int
main (void) main (void)
{ {
int a[DIM][DIM]; /* { dg-error "size of array 'a' is too large" } */ 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" } */
} }
...@@ -6,4 +6,3 @@ void Dispatcher() ...@@ -6,4 +6,3 @@ void Dispatcher()
/* { dg-error "expected type" "expected 1" { target *-*-* } 4 } */ /* { dg-error "expected type" "expected 1" { target *-*-* } 4 } */
/* { dg-error "expected `,' before" "expected 2" { target *-*-* } 4 } */ /* { dg-error "expected `,' before" "expected 2" { target *-*-* } 4 } */
/* { dg-error "expected `\\\)" "expected 3" { target *-*-* } 4 } */ /* { dg-error "expected `\\\)" "expected 3" { target *-*-* } 4 } */
/* { dg-error "expected ',' or" "expected 4" { target *-*-* } 4 } */
...@@ -13,5 +13,5 @@ class S ...@@ -13,5 +13,5 @@ class S
template <class I> template <class I>
void S::Foo(int (*f)(TYPO&o) ) // { dg-error "Foo|f|TYPO|o" } void S::Foo(int (*f)(TYPO&o) ) // { dg-error "Foo|f|TYPO|o" }
{ // { dg-error "expected `;'" } {
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment