This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: c++ enable checking failure 3
I see. Still, I feel that changing current_class_depth for namespace
members is a bad idea. Instead, I've produced another patch.
g++.ns/lookup4.C should cover all interesting cases, please let me
know if I missed some.
Regards,
Martin
1998-07-11 Martin von Löwis <loewis@informatik.hu-berlin.de>
* class.c (push_nested_class): Complain about namespaces.
* decl.c (start_decl): Enter the object's namespace.
(cp_finish_decl): Leave it.
(grokdeclarator): Likewise.
* decl2.c (check_decl_namespace): New function.
(finish_file): Call it.
* parse.y (complex_direct_notype_declarator): Set complexity
of namespace-qualified ids to -1, enter the namespace.
Index: decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.149
diff -c -p -r1.149 decl.c
*** decl.c 1998/07/08 12:16:02 1.149
--- decl.c 1998/07/11 16:30:56
*************** start_decl (declarator, declspecs, initi
*** 6223,6228 ****
--- 6283,6296 ----
? DECL_CLASS_CONTEXT (decl)
: DECL_CONTEXT (decl);
+ if (initialized && context && TREE_CODE (context) == NAMESPACE_DECL
+ && context != current_namespace && TREE_CODE (decl) == VAR_DECL)
+ {
+ /* When parsing the initializer, lookup should use the object's
+ namespace. */
+ push_decl_namespace (context);
+ }
+
/* We are only interested in class contexts, later. */
if (context && TREE_CODE (context) == NAMESPACE_DECL)
context = NULL_TREE;
*************** cp_finish_decl (decl, init, asmspec_tree
*** 6678,6683 ****
--- 6746,6761 ----
init = NULL_TREE;
}
+ if (TREE_CODE (decl) == VAR_DECL
+ && DECL_CONTEXT (decl)
+ && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL
+ && DECL_CONTEXT (decl) != current_namespace
+ && init)
+ {
+ /* Leave the namespace of the object. */
+ pop_decl_namespace ();
+ }
+
/* If the type of the thing we are declaring either has
a constructor, or has a virtual function table pointer,
AND its initialization was accepted by `start_decl',
*************** grokdeclarator (declarator, declspecs, d
*** 9478,9483 ****
--- 9556,9564 ----
if (TREE_COMPLEXITY (declarator) == 0)
/* This needs to be here, in case we are called
multiple times. */ ;
+ else if (TREE_COMPLEXITY (declarator) == -1)
+ /* Namespace member. */
+ pop_decl_namespace ();
else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
/* Don't fall out into global scope. Hides real bug? --eichin */ ;
else if (! IS_AGGR_TYPE_CODE
Index: decl2.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl2.c,v
retrieving revision 1.93
diff -c -p -r1.93 decl2.c
*** decl2.c 1998/07/08 12:16:04 1.93
--- decl2.c 1998/07/11 16:38:12
*************** static tree namespace_ancestor PROTO((tr
*** 62,67 ****
--- 62,68 ----
static void add_using_namespace PROTO((tree, tree, int));
static tree ambiguous_decl PROTO((tree, tree, tree));
static tree build_anon_union_vars PROTO((tree, tree*, int, int));
+ static void check_decl_namespace PROTO((void));
extern int current_class_depth;
*************** finish_file ()
*** 3125,3130 ****
--- 3126,3133 ----
if (! global_bindings_p () || current_class_type)
return;
+ check_decl_namespace ();
+
start_time = get_run_time ();
/* Otherwise, GDB can get confused, because in only knows
*************** pop_decl_namespace ()
*** 4115,4120 ****
--- 4119,4130 ----
decl_namespace_list = TREE_CHAIN (decl_namespace_list);
}
+ static void
+ check_decl_namespace ()
+ {
+ my_friendly_assert (decl_namespace_list == NULL_TREE, 980711);
+ }
+
/* [basic.lookup.koenig] */
/* A non-zero return value in the functions below indicates an error.
All nodes allocated in the procedure are on the scratch obstack. */
Index: class.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/class.c,v
retrieving revision 1.63
diff -c -p -r1.63 class.c
*** class.c 1998/07/07 11:24:43 1.63
--- class.c 1998/07/11 16:31:08
*************** push_nested_class (type, modify)
*** 4856,4862 ****
{
tree context;
! if (type == NULL_TREE || type == error_mark_node || ! IS_AGGR_TYPE (type)
|| TREE_CODE (type) == TEMPLATE_TYPE_PARM
|| TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM)
return;
--- 4856,4865 ----
{
tree context;
! my_friendly_assert (!type || TREE_CODE (type) != NAMESPACE_DECL, 980711);
!
! if (type == NULL_TREE || type == error_mark_node
! || ! IS_AGGR_TYPE (type)
|| TREE_CODE (type) == TEMPLATE_TYPE_PARM
|| TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM)
return;
Index: parse.y
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/parse.y,v
retrieving revision 1.66
diff -c -p -r1.66 parse.y
*** parse.y 1998/07/07 11:25:00 1.66
--- parse.y 1998/07/11 16:31:10
*************** complex_direct_notype_declarator:
*** 2755,2762 ****
| direct_notype_declarator '[' ']'
{ $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
| notype_qualified_id
! { if (OP0 ($1) != current_class_type)
{
push_nested_class (OP0 ($1), 3);
TREE_COMPLEXITY ($1) = current_class_depth;
}
--- 2791,2803 ----
| 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;
}