call.c (joust): Don't warn about "confusing" conversions to the same type.

* call.c (joust): Don't warn about "confusing" conversions to the
	same type.
	* 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.
	* method.c (build_template_decl_overload): Expect _DECL as first
	parameter. Put context temporarily into current_namespace.
	* pt.c (check_explicit_specialization): Change caller.
	(tsubst): Likewise.
	* init.c (build_offset_ref): Call mark_used and
	convert_from_reference for namespace members.

From-SVN: r21135
This commit is contained in:
Jason Merrill 1998-07-14 08:09:17 -04:00
parent b33cfabac1
commit 9a68c51f56
10 changed files with 337 additions and 254 deletions

View File

@ -1,3 +1,27 @@
1998-07-14 Jason Merrill <jason@yorick.cygnus.com>
* call.c (joust): Don't warn about "confusing" conversions to the
same type.
1998-07-14 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.
* method.c (build_template_decl_overload): Expect _DECL as first
parameter. Put context temporarily into current_namespace.
* pt.c (check_explicit_specialization): Change caller.
(tsubst): Likewise.
* init.c (build_offset_ref): Call mark_used and
convert_from_reference for namespace members.
Mon Jul 13 23:25:28 1998 Martin von Lvwis <loewis@informatik.hu-berlin.de>
* search.c (my_tree_cons): The bitfield is at index 2.

View File

@ -4314,10 +4314,16 @@ joust (cand1, cand2, warn)
}
}
/* warn about confusing overload resolution */
/* warn about confusing overload resolution for user-defined conversions,
either between a constructor and a conversion op, or between two
conversion ops. */
if (winner && cand1->second_conv
&& (! DECL_CONSTRUCTOR_P (cand1->fn)
|| ! DECL_CONSTRUCTOR_P (cand2->fn)))
&& ((DECL_CONSTRUCTOR_P (cand1->fn)
!= DECL_CONSTRUCTOR_P (cand2->fn))
/* Don't warn if the two conv ops convert to the same type... */
|| (! DECL_CONSTRUCTOR_P (cand1->fn)
&& ! comptypes (TREE_TYPE (cand1->second_conv),
TREE_TYPE (cand2->second_conv), 1))))
{
int comp = compare_ics (cand1->second_conv, cand2->second_conv);
if (comp != winner)

View File

@ -4858,9 +4858,7 @@ push_nested_class (type, modify)
{
tree context;
/* FIXME should handle namespaces like classes. */
if (TREE_CODE (type) == NAMESPACE_DECL)
return;
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

View File

@ -6270,6 +6270,14 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes)
? 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;
@ -6725,6 +6733,16 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
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',
@ -9524,6 +9542,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
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

View File

@ -62,6 +62,7 @@ static tree namespace_ancestor PROTO((tree, tree));
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;
@ -3125,6 +3126,8 @@ finish_file ()
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
@ -4116,6 +4119,12 @@ pop_decl_namespace ()
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. */

View File

@ -1538,7 +1538,11 @@ build_offset_ref (type, name)
/* Handle namespace names fully here. */
if (TREE_CODE (type) == NAMESPACE_DECL)
return lookup_namespace_name (type, name);
{
t = lookup_namespace_name (type, name);
mark_used (t);
return convert_from_reference (t);
}
if (type == NULL_TREE || ! is_aggr_type (type, 1))
return error_mark_node;

View File

@ -1657,17 +1657,31 @@ build_decl_overload (dname, parms, for_method)
/* Like build_decl_overload, but for template functions. */
tree
build_template_decl_overload (dname, parms, ret_type, tparms, targs,
build_template_decl_overload (decl, parms, ret_type, tparms, targs,
for_method)
tree dname;
tree decl;
tree parms;
tree ret_type;
tree tparms;
tree targs;
int for_method;
{
return build_decl_overload_real (dname, parms, ret_type, tparms, targs,
for_method);
tree res, saved_ctx;
/* If the template is in a namespace, we need to put that into the
mangled name. Unfortunately, build_decl_overload_real does not
get the decl to mangle, so it relies on the current
namespace. Therefore, we set that here temporarily. */
my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd', 980702);
saved_ctx = current_namespace;
current_namespace = CP_DECL_CONTEXT (decl);
res = build_decl_overload_real (DECL_NAME (decl), parms, ret_type,
tparms, targs, for_method);
current_namespace = saved_ctx;
return res;
}

File diff suppressed because it is too large Load Diff

View File

@ -2786,7 +2786,12 @@ complex_direct_notype_declarator:
| direct_notype_declarator '[' ']'
{ $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
| notype_qualified_id
{ if (OP0 ($1) != current_class_type)
{ 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;

View File

@ -1220,9 +1220,7 @@ check_explicit_specialization (declarator, decl, template_count, flags)
DECL_ASSEMBLER_NAME (decl)
= build_template_decl_overload
(DECL_NAME (decl),
arg_types,
TREE_TYPE (TREE_TYPE (tmpl)),
(decl, arg_types, TREE_TYPE (TREE_TYPE (tmpl)),
DECL_INNERMOST_TEMPLATE_PARMS (tmpl),
targs, ctype != NULL_TREE);
}
@ -4783,8 +4781,7 @@ tsubst (t, args, in_decl)
DECL_ASSEMBLER_NAME (r)
= build_template_decl_overload
(DECL_NAME (r), arg_types,
TREE_TYPE (TREE_TYPE (tmpl)),
(r, arg_types, TREE_TYPE (TREE_TYPE (tmpl)),
tparms, targs, member);
}
}