Commit ed2fa432 by Jason Merrill Committed by Jason Merrill

re PR c++/4003 (ICE on template instantiation including friendship declaration.)

        PR c++/4003
        * pt.c (tsubst_friend_function): Use decl_namespace_context.

From-SVN: r50966
parent fd70bb64
2002-03-18 Jason Merrill <jason@redhat.com> 2002-03-18 Jason Merrill <jason@redhat.com>
PR c++/4003 - template/friend.C
* pt.c (tsubst_friend_function): Use decl_namespace_context.
PR c++/3948 -- C++ ABI change, followup to 2001-12-18 patch. PR c++/3948 -- C++ ABI change, followup to 2001-12-18 patch.
* class.c (finish_struct_bits): Also set TREE_ADDRESSABLE for a * class.c (finish_struct_bits): Also set TREE_ADDRESSABLE for a
type with a nontrivial destructor. type with a nontrivial destructor.
......
...@@ -4623,7 +4623,7 @@ tsubst_friend_function (decl, args) ...@@ -4623,7 +4623,7 @@ tsubst_friend_function (decl, args)
tree template_id, arglist, fns; 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)); tree ns = decl_namespace_context (TYPE_MAIN_DECL (current_class_type));
/* Friend functions are looked up in the containing namespace scope. /* Friend functions are looked up in the containing namespace scope.
We must enter that scope, to avoid finding member functions of the We must enter that scope, to avoid finding member functions of the
...@@ -6064,15 +6064,6 @@ tsubst_decl (t, args, type, complain) ...@@ -6064,15 +6064,6 @@ tsubst_decl (t, args, type, complain)
SET_DECL_RTL (r, NULL_RTX); SET_DECL_RTL (r, NULL_RTX);
DECL_SIZE (r) = DECL_SIZE_UNIT (r) = 0; DECL_SIZE (r) = DECL_SIZE_UNIT (r) = 0;
/* For __PRETTY_FUNCTION__ we have to adjust the initializer. */
if (DECL_PRETTY_FUNCTION_P (r))
{
const char *const name = (*decl_printable_name)
(current_function_decl, 2);
DECL_INITIAL (r) = cp_fname_init (name);
TREE_TYPE (r) = TREE_TYPE (DECL_INITIAL (r));
}
/* Even if the original location is out of scope, the newly /* Even if the original location is out of scope, the newly
substituted one is not. */ substituted one is not. */
if (TREE_CODE (r) == VAR_DECL) if (TREE_CODE (r) == VAR_DECL)
...@@ -7353,10 +7344,6 @@ tsubst_expr (t, args, complain, in_decl) ...@@ -7353,10 +7344,6 @@ tsubst_expr (t, args, complain, in_decl)
{ {
init = DECL_INITIAL (decl); init = DECL_INITIAL (decl);
decl = tsubst (decl, args, complain, in_decl); decl = tsubst (decl, args, complain, in_decl);
if (DECL_PRETTY_FUNCTION_P (decl))
init = DECL_INITIAL (decl);
else
init = tsubst_expr (init, args, complain, in_decl);
if (decl != error_mark_node) if (decl != error_mark_node)
{ {
if (TREE_CODE (decl) != TYPE_DECL) if (TREE_CODE (decl) != TYPE_DECL)
...@@ -7372,6 +7359,17 @@ tsubst_expr (t, args, complain, in_decl) ...@@ -7372,6 +7359,17 @@ tsubst_expr (t, args, complain, in_decl)
if (TREE_CODE (decl) == VAR_DECL) if (TREE_CODE (decl) == VAR_DECL)
DECL_TEMPLATE_INSTANTIATED (decl) = 1; DECL_TEMPLATE_INSTANTIATED (decl) = 1;
maybe_push_decl (decl); maybe_push_decl (decl);
if (DECL_PRETTY_FUNCTION_P (decl))
{
/* For __PRETTY_FUNCTION__ we have to adjust the
initializer. */
const char *const name
= (*decl_printable_name) (current_function_decl, 2);
init = cp_fname_init (name);
TREE_TYPE (decl) = TREE_TYPE (init);
}
else
init = tsubst_expr (init, args, complain, in_decl);
cp_finish_decl (decl, init, NULL_TREE, 0); cp_finish_decl (decl, init, NULL_TREE, 0);
} }
} }
......
...@@ -16,15 +16,15 @@ ostream& operator<<(ostream &o, const typename s<T>::t &x) ...@@ -16,15 +16,15 @@ ostream& operator<<(ostream &o, const typename s<T>::t &x)
template <class T> template <class T>
struct s { struct s {
struct t struct t
{ // { dg-bogus "" "" { xfail *-*-* } } {
friend ostream& friend ostream&
operator<<<T>(ostream&, const typename s<T>::t &); // { dg-bogus "" "" { xfail *-*-* } } operator<<<T>(ostream&, const typename s<T>::t &);
}; };
t x; t x;
}; };
int main() int main()
{ {
s<int>::t y; // { dg-bogus "" "" { xfail *-*-* } } s<int>::t y;
cout << y; cout << y;
} }
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