]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Backport:
authorVolker Reichelt <reichelt@igpm.rwth-aachen.de>
Mon, 5 Dec 2005 18:01:05 +0000 (18:01 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Mon, 5 Dec 2005 18:01:05 +0000 (18:01 +0000)
2005-10-13  Mark Mitchell  <mark@codesourcery.com>

PR c++/22352
* pt.c (tsubst_template_parms): Set processing_template_decl while
processing the parameters.
(tsubst_decl): Set processing_template_decl when substituting into
a TEMPLATE_DECL.

* g++.dg/template/friend38.C: New test.

From-SVN: r108066

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/friend38.C [new file with mode: 0644]

index ae8cad7bf6ba46f7a2c9f866072b7be86c155e34..e9767a957fc0807e6de4c537d9824758ecf14a2b 100644 (file)
@@ -1,3 +1,14 @@
+2005-12-05  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+       Backport:
+       2005-10-13  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/22352
+       * pt.c (tsubst_template_parms): Set processing_template_decl while
+       processing the parameters.
+       (tsubst_decl): Set processing_template_decl when substituting into
+       a TEMPLATE_DECL.
+
 2005-12-05  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        Backport:
index b547cefbda9a8a3429673f2f5c60ddf185be69d3..e916c3786d738bb575f5cb3fa417035ba63dfca7 100644 (file)
@@ -5785,6 +5785,12 @@ tsubst_template_parms (tree parms, tree args, tsubst_flags_t complain)
   tree r = NULL_TREE;
   tree* new_parms;
 
+  /* When substituting into a template, we must set
+     PROCESSING_TEMPLATE_DECL as the template parameters may be
+     dependent if they are based on one-another, and the dependency
+     predicates are short-circuit outside of templates.  */
+  ++processing_template_decl;
+
   for (new_parms = &r;
        TMPL_PARMS_DEPTH (parms) > TMPL_ARGS_DEPTH (args);
        new_parms = &(TREE_CHAIN (*new_parms)),
@@ -5814,6 +5820,8 @@ tsubst_template_parms (tree parms, tree args, tsubst_flags_t complain)
                   new_vec, NULL_TREE);
     }
 
+  --processing_template_decl;
+
   return r;
 }
 
@@ -5999,8 +6007,14 @@ tsubst_decl (tree t, tree args, tree type, tsubst_flags_t complain)
              : DECL_TI_ARGS (DECL_TEMPLATE_RESULT (t));
            tree full_args;
            
+           /* Because this is a template, the arguments will still be
+              dependent, even after substitution.  If
+              PROCESSING_TEMPLATE_DECL is not set, the dependency
+              predicates will short-circuit.  */
+           ++processing_template_decl;
            full_args = tsubst_template_args (tmpl_args, args,
                                              complain, in_decl);
+           --processing_template_decl;
 
            /* tsubst_template_args doesn't copy the vector if
               nothing changed.  But, *something* should have
@@ -6032,15 +6046,14 @@ tsubst_decl (tree t, tree args, tree type, tsubst_flags_t complain)
            break;
          }
 
-       DECL_CONTEXT (r) 
-         = tsubst_aggr_type (DECL_CONTEXT (t), args, 
-                             complain, in_decl, 
-                             /*entering_scope=*/1); 
        DECL_TEMPLATE_INFO (r) = build_tree_list (t, args);
 
        if (TREE_CODE (decl) == TYPE_DECL)
          {
-           tree new_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
+           tree new_type;
+           ++processing_template_decl;
+           new_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
+           --processing_template_decl; 
            if (new_type == error_mark_node)
              return error_mark_node;
 
@@ -6048,10 +6061,14 @@ tsubst_decl (tree t, tree args, tree type, tsubst_flags_t complain)
            CLASSTYPE_TI_TEMPLATE (new_type) = r;
            DECL_TEMPLATE_RESULT (r) = TYPE_MAIN_DECL (new_type);
            DECL_TI_ARGS (r) = CLASSTYPE_TI_ARGS (new_type);
+           DECL_CONTEXT (r) = TYPE_CONTEXT (new_type);
          }
        else
          {
-           tree new_decl = tsubst (decl, args, complain, in_decl);
+           tree new_decl;
+           ++processing_template_decl;
+           new_decl = tsubst (decl, args, complain, in_decl);
+           --processing_template_decl;
            if (new_decl == error_mark_node)
              return error_mark_node;
 
@@ -6059,6 +6076,7 @@ tsubst_decl (tree t, tree args, tree type, tsubst_flags_t complain)
            DECL_TI_TEMPLATE (new_decl) = r;
            TREE_TYPE (r) = TREE_TYPE (new_decl);
            DECL_TI_ARGS (r) = DECL_TI_ARGS (new_decl);
+           DECL_CONTEXT (r) = DECL_CONTEXT (new_decl); 
          }
 
        SET_DECL_IMPLICIT_INSTANTIATION (r);
index 7063568386a56b9b20bafca14d2b61f94f5d6775..919ebd5fdad7ccf3196fb26f9eeed95a473deef6 100644 (file)
@@ -1,3 +1,11 @@
+2005-12-05  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+       Backport:
+       2005-10-13  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/22352
+       * g++.dg/template/friend38.C: New test.
+
 2005-12-05  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        Backport:
diff --git a/gcc/testsuite/g++.dg/template/friend38.C b/gcc/testsuite/g++.dg/template/friend38.C
new file mode 100644 (file)
index 0000000..41faf79
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/22352
+
+template <class A>
+class s
+{
+  typedef int d;
+  template <class s, typename s::d>
+  friend class t;
+};
+
+s<int> t1;
+