method.c (build_decl_overload_real): Fix namespace handling.

* method.c (build_decl_overload_real): Fix namespace handling.
	* typeck.c (build_unary_op): Extract a lone function from an
	OVERLOAD.
	* call.c (build_scoped_method_call): Handle getting a namespace
	for basetype in a destructor call.
	(check_dtor_name): Handle enums.
	* parse.y (using_directive): New nonterminal.
	(extdef, simple_stmt): Use it.

From-SVN: r21174
This commit is contained in:
Jason Merrill 1998-07-15 04:38:53 +00:00 committed by Jason Merrill
parent 8508a96d6b
commit 268775847c
6 changed files with 4471 additions and 4433 deletions

View file

@ -1,3 +1,17 @@
1998-07-15 Jason Merrill <jason@yorick.cygnus.com>
* method.c (build_decl_overload_real): Fix namespace handling.
* typeck.c (build_unary_op): Extract a lone function from an
OVERLOAD.
* call.c (build_scoped_method_call): Handle getting a namespace
for basetype in a destructor call.
(check_dtor_name): Handle enums.
* parse.y (using_directive): New nonterminal.
(extdef, simple_stmt): Use it.
1998-07-14 Martin von Löwis <loewis@informatik.hu-berlin.de>
* decl2.c (add_function): Move error message ...

View file

@ -356,7 +356,9 @@ check_dtor_name (basetype, name)
/* OK */;
else if (TREE_CODE (name) == IDENTIFIER_NODE)
{
if (IS_AGGR_TYPE (basetype) && name == constructor_name (basetype))
if ((IS_AGGR_TYPE (basetype) && name == constructor_name (basetype))
|| (TREE_CODE (basetype) == ENUMERAL_TYPE
&& name == TYPE_IDENTIFIER (basetype)))
name = basetype;
else
name = get_type_value (name);
@ -414,20 +416,29 @@ build_scoped_method_call (exp, basetype, name, parms)
binfo = NULL_TREE;
/* Check the destructor call syntax. */
if (TREE_CODE (name) == BIT_NOT_EXPR && ! check_dtor_name (basetype, name))
cp_error ("qualified type `%T' does not match destructor name `~%T'",
basetype, TREE_OPERAND (name, 0));
/* Destructors can be "called" for simple types; see 5.2.4 and 12.4 Note
that explicit ~int is caught in the parser; this deals with typedefs
and template parms. */
if (TREE_CODE (name) == BIT_NOT_EXPR && ! IS_AGGR_TYPE (basetype))
if (TREE_CODE (name) == BIT_NOT_EXPR)
{
if (TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (basetype))
cp_error ("type of `%E' does not match destructor type `%T' (type was `%T')",
exp, basetype, type);
return cp_convert (void_type_node, exp);
/* We can get here if someone writes their destructor call like
`obj.NS::~T()'; this isn't really a scoped method call, so hand
it off. */
if (TREE_CODE (basetype) == NAMESPACE_DECL)
return build_method_call (exp, name, parms, NULL_TREE, LOOKUP_NORMAL);
if (! check_dtor_name (basetype, name))
cp_error ("qualified type `%T' does not match destructor name `~%T'",
basetype, TREE_OPERAND (name, 0));
/* Destructors can be "called" for simple types; see 5.2.4 and 12.4 Note
that explicit ~int is caught in the parser; this deals with typedefs
and template parms. */
if (! IS_AGGR_TYPE (basetype))
{
if (TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (basetype))
cp_error ("type of `%E' does not match destructor type `%T' (type was `%T')",
exp, basetype, type);
return cp_convert (void_type_node, exp);
}
}
if (! is_aggr_type (basetype, 1))

View file

@ -1539,7 +1539,8 @@ build_decl_overload_real (dname, parms, ret_type, tparms, targs,
as the declaration. Unfortunately, we don't have the _DECL,
only its name */
OB_PUTC ('F');
else if (!for_method)
if (!for_method && current_namespace != global_namespace)
/* qualify with namespace */
build_qualified_name (current_namespace);

File diff suppressed because it is too large Load diff

View file

@ -405,7 +405,7 @@ extdef:
{ pop_namespace (); }
| NAMESPACE identifier '='
{ begin_only_namespace_names (); }
any_id ';'
any_id ';'
{
end_only_namespace_names ();
if (lastiddecl)
@ -414,18 +414,7 @@ extdef:
}
| using_decl ';'
{ do_toplevel_using_decl ($1); }
| USING NAMESPACE
{ begin_only_namespace_names (); }
any_id ';'
{
end_only_namespace_names ();
/* If no declaration was found, the using-directive is
invalid. Since that was not reported, we need the
identifier for the error message. */
if (TREE_CODE ($4) == IDENTIFIER_NODE && lastiddecl)
$4 = lastiddecl;
do_using_directive ($4);
}
| using_directive
| extension extdef
{ pedantic = $<itype>1; }
;
@ -448,6 +437,21 @@ namespace_using_decl:
{ $$ = build_parse_node (SCOPE_REF, $3, $4); }
;
using_directive:
USING NAMESPACE
{ begin_only_namespace_names (); }
any_id ';'
{
end_only_namespace_names ();
/* If no declaration was found, the using-directive is
invalid. Since that was not reported, we need the
identifier for the error message. */
if (TREE_CODE ($4) == IDENTIFIER_NODE && lastiddecl)
$4 = lastiddecl;
do_using_directive ($4);
}
;
namespace_qualifier:
NSNAME SCOPE
{
@ -3281,12 +3285,7 @@ simple_stmt:
| ';'
{ finish_stmt (); }
| try_block
| USING NAMESPACE any_id ';'
{
if (TREE_CODE ($3) == IDENTIFIER_NODE && lastiddecl)
$3 = lastiddecl;
do_using_directive ($3);
}
| using_directive
| namespace_using_decl
{ do_local_using_decl ($1); }
;

View file

@ -4547,6 +4547,14 @@ build_unary_op (code, xarg, noconvert)
return build1 (ADDR_EXPR, unknown_type_node, arg);
}
/* If we have a single function from a using decl, pull it out. */
if (TREE_CODE (arg) == OVERLOAD
&& ! really_overloaded_fn (arg))
{
arg = OVL_FUNCTION (arg);
argtype = TREE_TYPE (arg);
}
if (TREE_CODE (arg) == OVERLOAD
|| (TREE_CODE (arg) == OFFSET_REF
&& TREE_CODE (TREE_OPERAND (arg, 1)) == TEMPLATE_ID_EXPR))