re PR c++/4003 (ICE on template instantiation including friendship declaration.)
authorJason Merrill <jason@redhat.com>
Mon, 18 Mar 2002 13:27:03 +0000 (08:27 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 18 Mar 2002 13:27:03 +0000 (08:27 -0500)
        PR c++/4003
        * pt.c (tsubst_friend_function): Use decl_namespace_context.

From-SVN: r50966

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/template/friend.C

index 8fc4c80c3e7b275b4805564f9ae9dc6a8a6ecb1e..632a25726a8d8a96446062a897599d6276f58db5 100644 (file)
@@ -1,5 +1,8 @@
 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.
        * class.c (finish_struct_bits): Also set TREE_ADDRESSABLE for a
        type with a nontrivial destructor.
index 7e82b44cd613808b8040eeccdf6b46d1946d82ff..67da22daa9a9a988e11c07fa65a59621266a7143 100644 (file)
@@ -4623,7 +4623,7 @@ tsubst_friend_function (decl, args)
       tree template_id, arglist, fns;
       tree new_args;
       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.
          We must enter that scope, to avoid finding member functions of the
@@ -6064,15 +6064,6 @@ tsubst_decl (t, args, type, complain)
        SET_DECL_RTL (r, NULL_RTX);
        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
           substituted one is not.  */
        if (TREE_CODE (r) == VAR_DECL)
@@ -7353,10 +7344,6 @@ tsubst_expr (t, args, complain, in_decl)
          {
            init = DECL_INITIAL (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 (TREE_CODE (decl) != TYPE_DECL)
@@ -7372,6 +7359,17 @@ tsubst_expr (t, args, complain, in_decl)
                if (TREE_CODE (decl) == VAR_DECL)
                  DECL_TEMPLATE_INSTANTIATED (decl) = 1;
                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);
              }
          }
index 67f575e0bef749b439c033d1677c76b4ae1ea9a4..59564ad94372efaf808ed49db1a3ba12f37b370b 100644 (file)
@@ -16,15 +16,15 @@ ostream& operator<<(ostream &o, const typename s<T>::t &x)
 template <class T>
 struct s {
   struct t
-  {                             // { dg-bogus "" "" { xfail *-*-* } }
+  {
     friend ostream&
-    operator<<<T>(ostream&, const typename s<T>::t &); // { dg-bogus "" "" { xfail *-*-* } }
+    operator<<<T>(ostream&, const typename s<T>::t &);
   };
   t x;
 };
 
 int main()
 {
-  s<int>::t y;                  // { dg-bogus "" "" { xfail *-*-* } }
+  s<int>::t y;
   cout << y;
 }