This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR c++/3882


> Looking more closely, it seems that if we just move the init-setting code
> later, the PRETTY_FUNCTION case will be broken, as in that case we set
> init from DECL_INITIAL, which we will have just set to error_mark_node.
> The fix for this, IMO, is to move the code to generate the PRETTY_FUNCTION
> initializer from tsubst_decl to here.

And that's more elegant than propagating the special PRETTY_FUNCTION case.
Thanks for the tip.

No (new) regression on i586-pc-linux-gnu.


2002-03-18  Eric Botcazou  <ebotcazou@multimania.com>

 PR c++/3882
 * cp/pt.c (tsubst_decl): Move __PRETTY_FUNCTION__
 handling...
 (tsubst_expr, case DECL_STMT): ...here. And
 substitute the initializer only after recording
 the declaration.


===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.579
diff -u -r1.579 pt.c
--- gcc/cp/pt.c 16 Mar 2002 18:30:13 -0000 1.579
+++ gcc/cp/pt.c 18 Mar 2002 18:21:50 -0000
@@ -6064,15 +6029,6 @@
  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 +7309,6 @@
    {
      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 +7324,16 @@
          if (TREE_CODE (decl) == VAR_DECL)
            DECL_TEMPLATE_INSTANTIATED (decl) = 1;
          maybe_push_decl (decl);
+         /* For __PRETTY_FUNCTION__ we have to adjust the initializer. */
+         if (DECL_PRETTY_FUNCTION_P (decl))
+           {
+             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);
        }
    }


/* PR c++/3882 */
/* { dg-do compile } */
/* { dg-options "" } */

/* Verify that variable initialization can be
   self-referencing inside a function template. */

int foo(int);

template <typename T>
void bar(const T&)
{
  int i = foo(i);
}

void quus()
{
   bar(0);
}


--
Eric Botcazou
ebotcazou@multimania.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]