Commit 76e57b45 by Nathan Sidwell Committed by Nathan Sidwell

decl.c (grokfndecl): Undo COMPONENT_REF damage caused by bison parser ickiness.

cp:
	* decl.c (grokfndecl): Undo COMPONENT_REF damage caused by
	bison parser ickiness.
	* pt.c (tsubst_friend_function): Enter namespace scope when
	tsubsting the function name.
	* cp-tree.h (DECL_TI_TEMPLATE): Update comment to reflect reality.
testsuite:
	* g++.old-deja/g++.other/friend46.C: New test.

From-SVN: r37793
parent 70bbeb8b
2000-11-27 Nathan Sidwell <nathan@codesourcery.com> 2000-11-27 Nathan Sidwell <nathan@codesourcery.com>
* decl.c (grokfndecl): Undo COMPONENT_REF damage caused by
bison parser ickiness.
* pt.c (tsubst_friend_function): Enter namespace scope when
tsubsting the function name.
* cp-tree.h (DECL_TI_TEMPLATE): Update comment to reflect reality.
2000-11-27 Nathan Sidwell <nathan@codesourcery.com>
* cp-tree.h (binfo_from_vbase): Return the virtual base's binfo. * cp-tree.h (binfo_from_vbase): Return the virtual base's binfo.
* cvt.c (cp_convert_to_pointer): Add force parameter. * cvt.c (cp_convert_to_pointer): Add force parameter.
Allow conversions via virtual base if forced. Allow conversions via virtual base if forced.
......
...@@ -2362,8 +2362,9 @@ struct lang_decl ...@@ -2362,8 +2362,9 @@ struct lang_decl
As a special case, for a member friend template of a template As a special case, for a member friend template of a template
class, this value will not be a TEMPLATE_DECL, but rather a class, this value will not be a TEMPLATE_DECL, but rather a
LOOKUP_EXPR or IDENTIFIER_NODE indicating the name of the template LOOKUP_EXPR, IDENTIFIER_NODE or OVERLOAD indicating the name of
and any explicit template arguments provided. For example, in: the template and any explicit template arguments provided. For
example, in:
template <class T> struct S { friend void f<int>(int, double); } template <class T> struct S { friend void f<int>(int, double); }
......
...@@ -8944,6 +8944,9 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, ...@@ -8944,6 +8944,9 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals,
orig_declarator); orig_declarator);
else else
{ {
tree fns = TREE_OPERAND (orig_declarator, 0);
tree args = TREE_OPERAND (orig_declarator, 1);
if (PROCESSING_REAL_TEMPLATE_DECL_P ()) if (PROCESSING_REAL_TEMPLATE_DECL_P ())
{ {
/* Something like `template <class T> friend void f<T>()'. */ /* Something like `template <class T> friend void f<T>()'. */
...@@ -8956,10 +8959,22 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, ...@@ -8956,10 +8959,22 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals,
/* A friend declaration of the form friend void f<>(). Record /* A friend declaration of the form friend void f<>(). Record
the information in the TEMPLATE_ID_EXPR. */ the information in the TEMPLATE_ID_EXPR. */
SET_DECL_IMPLICIT_INSTANTIATION (decl); SET_DECL_IMPLICIT_INSTANTIATION (decl);
DECL_TEMPLATE_INFO (decl)
= tree_cons (TREE_OPERAND (orig_declarator, 0), if (TREE_CODE (fns) == COMPONENT_REF)
TREE_OPERAND (orig_declarator, 1), {
NULL_TREE); /* Due to bison parser ickiness, we will have already looked
up an operator_name or PFUNCNAME within the current class
(see template_id in parse.y). If the current class contains
such a name, we'll get a COMPONENT_REF here. Undo that. */
my_friendly_assert (TREE_TYPE (TREE_OPERAND (fns, 0))
== current_class_type, 20001120);
fns = TREE_OPERAND (fns, 1);
}
my_friendly_assert (TREE_CODE (fns) == IDENTIFIER_NODE
|| TREE_CODE (fns) == LOOKUP_EXPR
|| TREE_CODE (fns) == OVERLOAD, 20001120);
DECL_TEMPLATE_INFO (decl) = tree_cons (fns, args, NULL_TREE);
if (has_default_arg) if (has_default_arg)
{ {
......
...@@ -4422,17 +4422,22 @@ tsubst_friend_function (decl, args) ...@@ -4422,17 +4422,22 @@ tsubst_friend_function (decl, args)
function declaration. Now, we have to figure out what function declaration. Now, we have to figure out what
instantiation of what template. */ instantiation of what template. */
{ {
tree template_id; tree template_id, arglist, fns;
tree new_args; tree new_args;
tree tmpl; tree tmpl;
tree ns = CP_DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
template_id
= lookup_template_function (tsubst_expr (DECL_TI_TEMPLATE (decl), /* Friend functions are looked up in the containing namespace scope.
args, /*complain=*/1, We must enter that scope, to avoid finding member functions of the
NULL_TREE), current cless with same name. */
tsubst (DECL_TI_ARGS (decl), push_nested_namespace (ns);
args, /*complain=*/1, fns = tsubst_expr (DECL_TI_TEMPLATE (decl), args,
NULL_TREE)); /*complain=*/1, NULL_TREE);
pop_nested_namespace (ns);
arglist = tsubst (DECL_TI_ARGS (decl), args,
/*complain=*/1, NULL_TREE);
template_id = lookup_template_function (fns, arglist);
new_friend = tsubst (decl, args, /*complain=*/1, NULL_TREE); new_friend = tsubst (decl, args, /*complain=*/1, NULL_TREE);
tmpl = determine_specialization (template_id, new_friend, tmpl = determine_specialization (template_id, new_friend,
&new_args, &new_args,
......
2000-11-27 Nathan Sidwell <nathan@codesourcery.com> 2000-11-27 Nathan Sidwell <nathan@codesourcery.com>
* g++.old-deja/g++.other/friend46.C: New test.
2000-11-27 Nathan Sidwell <nathan@codesourcery.com>
* g++.old-deja/g++.other/ptrmem8.C: New test. * g++.old-deja/g++.other/ptrmem8.C: New test.
2000-11-26 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 2000-11-26 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
......
// Build don't link:
// Copyright (C) 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 17 Nov 2000 <nathan@codesourcery.com>
// bug 43. Two failings, bison parser ickiness caused us to find the member
// named the same as a friend, and then when instantiating, we'd lookup in
// the wrong scope.
namespace X {
template <class T> class P;
template <class T> void operator- (const P<T>&);
template <class T>
struct V
{
V (const T&);
void operator- ();
friend void operator-<> (const P<T>& a);
};
}
int main()
{
X::V<double> b(1.0);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment