From 650fcd0729e2fcf4df28a46a6de4bc748724e2b1 Mon Sep 17 00:00:00 2001 From: Lee Millward <lee.millward@codesourcery.com> Date: Thu, 12 Oct 2006 20:02:53 +0000 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 10 ++++++++++ gcc/cp/class.c | 1 + gcc/cp/decl.c | 11 +++++++---- gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/g++.dg/other/large-size-array.C | 2 +- gcc/testsuite/g++.dg/parse/crash27.C | 1 - gcc/testsuite/g++.dg/template/crash1.C | 2 +- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1ac313bbf2b5..4102503dea8d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index fa11606f2d1c..e4bf89e3ddca 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -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); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index e95870dc6cf2..e814c0a4eb87 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b13454eb6cad..ce07d43a4f14 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 diff --git a/gcc/testsuite/g++.dg/other/large-size-array.C b/gcc/testsuite/g++.dg/other/large-size-array.C index 900c50331697..1385878d0c88 100644 --- a/gcc/testsuite/g++.dg/other/large-size-array.C +++ b/gcc/testsuite/g++.dg/other/large-size-array.C @@ -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" } */ } diff --git a/gcc/testsuite/g++.dg/parse/crash27.C b/gcc/testsuite/g++.dg/parse/crash27.C index 4d6517727d12..1a13f818f11d 100644 --- a/gcc/testsuite/g++.dg/parse/crash27.C +++ b/gcc/testsuite/g++.dg/parse/crash27.C @@ -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 } */ diff --git a/gcc/testsuite/g++.dg/template/crash1.C b/gcc/testsuite/g++.dg/template/crash1.C index 16d584e0fbb6..a500da18bde8 100644 --- a/gcc/testsuite/g++.dg/template/crash1.C +++ b/gcc/testsuite/g++.dg/template/crash1.C @@ -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 `;'" } +{ } -- GitLab