This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH for crash on bogus namepsace usage
- To: egcs-patches at cygnus dot com
- Subject: PATCH for crash on bogus namepsace usage
- From: Mark Mitchell <mark at markmitchell dot com>
- Date: Mon, 17 Aug 1998 22:34:11 -0700
- Cc: Jason Merrill <jason at cygnus dot com>
- Reply-to: mark at markmitchell dot com
This patch avoids an ICE on the attached test-case.
--
Mark Mitchell mark@markmitchell.com
Mark Mitchell Consulting http://www.markmitchell.com
1998-08-17 Mark Mitchell <mark@markmitchell.com>
* cp-tree.h (enter_scope_of): New function.
* parse.y (complex_direct_notype_declarator): Use it.
* semantics.c (enter_scope_of): New function.
Index: testsuite/g++.old-deja/g++.ns/crash1.C
===================================================================
RCS file: crash1.C
diff -N crash1.C
*** /dev/null Mon Dec 31 20:00:00 1979
--- crash1.C Mon Aug 17 16:28:10 1998
***************
*** 0 ****
--- 1,12 ----
+ // Build don't link:
+
+ template <class T>
+ struct S1 {};
+
+ namespace N {
+ }
+
+ struct S2
+ {
+ typedef N::S1<int> S2_T; // ERROR - parse error
+ };
Index: cp/cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.108
diff -c -p -r1.108 cp-tree.h
*** cp-tree.h 1998/08/06 16:56:37 1.108
--- cp-tree.h 1998/08/17 23:28:26
*************** extern void begin_inline_definitions
*** 2961,2966 ****
--- 2961,2967 ----
extern tree finish_member_class_template PROTO((tree, tree));
extern void finish_template_decl PROTO((tree));
extern tree finish_template_type PROTO((tree, tree, int));
+ extern void enter_scope_of PROTO((tree));
/* in sig.c */
extern tree build_signature_pointer_type PROTO((tree, int, int));
Index: cp/parse.y
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/parse.y,v
retrieving revision 1.78
diff -c -p -r1.78 parse.y
*** parse.y 1998/07/28 01:02:57 1.78
--- parse.y 1998/08/17 23:28:34
*************** complex_direct_notype_declarator:
*** 2818,2842 ****
| direct_notype_declarator '[' ']'
{ $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
| notype_qualified_id
! { if (TREE_CODE (OP0 ($1)) == NAMESPACE_DECL)
! {
! push_decl_namespace (OP0 ($1));
! TREE_COMPLEXITY ($1) = -1;
! }
! else if (OP0 ($1) != current_class_type)
! {
! push_nested_class (OP0 ($1), 3);
! TREE_COMPLEXITY ($1) = current_class_depth;
! }
! }
| nested_name_specifier notype_template_declarator
{ got_scope = NULL_TREE;
$$ = build_parse_node (SCOPE_REF, $1, $2);
! if ($1 != current_class_type)
! {
! push_nested_class ($1, 3);
! TREE_COMPLEXITY ($$) = current_class_depth;
! }
}
;
--- 2818,2828 ----
| direct_notype_declarator '[' ']'
{ $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
| notype_qualified_id
! { enter_scope_of ($1); }
| nested_name_specifier notype_template_declarator
{ got_scope = NULL_TREE;
$$ = build_parse_node (SCOPE_REF, $1, $2);
! enter_scope_of ($$);
}
;
Index: cp/semantics.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/semantics.c,v
retrieving revision 1.22
diff -c -p -r1.22 semantics.c
*** semantics.c 1998/07/31 15:01:18 1.22
--- semantics.c 1998/08/17 23:28:37
*************** finish_template_type (name, args, enteri
*** 1427,1429 ****
--- 1427,1450 ----
return decl;
}
+
+ /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
+ namespace scope or a class scope. */
+
+ void
+ enter_scope_of (sr)
+ tree sr;
+ {
+ tree scope = TREE_OPERAND (sr, 0);
+
+ if (TREE_CODE (scope) == NAMESPACE_DECL)
+ {
+ push_decl_namespace (scope);
+ TREE_COMPLEXITY (sr) = -1;
+ }
+ else if (scope != current_class_type)
+ {
+ push_nested_class (scope, 3);
+ TREE_COMPLEXITY (sr) = current_class_depth;
+ }
+ }