]> gcc.gnu.org Git - gcc.git/commitdiff
re PR c++/35 (template operator () lookup fails)
authorNathan Sidwell <nathan@codesourcery.com>
Wed, 2 Jan 2002 12:50:11 +0000 (12:50 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Wed, 2 Jan 2002 12:50:11 +0000 (12:50 +0000)
cp:
PR c++/35
* cp-tree.h (DECL_LANG_FLAG_0): Used for PARM_DECL too.
(DECL_TEMPLATE_PARM_P): A PARM_DECL might be one too.
* pt.c (process_template_parm): SET_DECL_TEMPLATE_PARM_P on the
PARM_DECL.
(tsubst_template_parms): Break up loop statements.
(tsubst_decl, case PARM_DECL): Copy DECL_TEMPLATE_PARM_P. Template
parm PARM_DECLs don't get promoted.
testsuite:
* g++.dg/template/ntp.C: New test.

From-SVN: r48470

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

index ef4c0ddf60d4cf3f4c701867172c9d5c9c805d24..4751ae9210cd1d95bbfa626f75b2dbf6245a0dee 100644 (file)
@@ -1,3 +1,14 @@
+2002-01-02  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/35
+       * cp-tree.h (DECL_LANG_FLAG_0): Used for PARM_DECL too.
+       (DECL_TEMPLATE_PARM_P): A PARM_DECL might be one too.
+       * pt.c (process_template_parm): SET_DECL_TEMPLATE_PARM_P on the
+       PARM_DECL.
+       (tsubst_template_parms): Break up loop statements.
+       (tsubst_decl, case PARM_DECL): Copy DECL_TEMPLATE_PARM_P. Template
+       parm PARM_DECLs don't get promoted.
+
 2002-01-02  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/5123
index 45b8fbfed40819f781e6649cb370c1d762fcc27e..f08f0ac1003727a4fd52b34d03d5f2c12e14bb77 100644 (file)
@@ -87,7 +87,7 @@ Boston, MA 02111-1307, USA.  */
 
    Usage of DECL_LANG_FLAG_?:
    0: DECL_ERROR_REPORTED (in VAR_DECL).
-      DECL_TEMPLATE_PARM_P (in CONST_DECL, TYPE_DECL, or TEMPLATE_DECL)
+      DECL_TEMPLATE_PARM_P (in PARM_DECL, CONST_DECL, TYPE_DECL, or TEMPLATE_DECL)
       DECL_LOCAL_FUNCTION_P (in FUNCTION_DECL)
       DECL_MUTABLE_P (in FIELD_DECL)
    1: C_TYPEDEF_EXPLICITLY_SIGNED (in TYPE_DECL).
@@ -2719,6 +2719,7 @@ enum ptrmemfunc_vbit_where_t
 #define DECL_TEMPLATE_PARM_P(NODE)             \
   (DECL_LANG_FLAG_0 (NODE)                     \
    && (TREE_CODE (NODE) == CONST_DECL          \
+       || TREE_CODE (NODE) == PARM_DECL                \
        || TREE_CODE (NODE) == TYPE_DECL                \
        || TREE_CODE (NODE) == TEMPLATE_DECL))
 
index 3a0921fefa0f9a63163179fa99addd5898a5917e..4f20635b5cb0f9ec0bda5ecce484d142e1e011e1 100644 (file)
@@ -1935,6 +1935,7 @@ process_template_parm (list, next)
       /* is a const-param */
       parm = grokdeclarator (TREE_VALUE (parm), TREE_PURPOSE (parm),
                             PARM, 0, NULL);
+      SET_DECL_TEMPLATE_PARM_P (parm);
 
       /* [temp.param]
 
@@ -5409,17 +5410,16 @@ tsubst_template_parms (parms, args, complain)
       
       for (i = 0; i < TREE_VEC_LENGTH (new_vec); ++i)
        {
-         tree default_value =
-           TREE_PURPOSE (TREE_VEC_ELT (TREE_VALUE (parms), i));
-         tree parm_decl = 
-           TREE_VALUE (TREE_VEC_ELT (TREE_VALUE (parms), i));
-         
-         TREE_VEC_ELT (new_vec, i)
-           = build_tree_list (maybe_fold_nontype_arg (
-                                 tsubst_expr (default_value, args, complain,
-                                              NULL_TREE)), 
-                              tsubst (parm_decl, args, complain,
-                                      NULL_TREE));
+         tree tuple = TREE_VEC_ELT (TREE_VALUE (parms), i);
+         tree default_value = TREE_PURPOSE (tuple);
+         tree parm_decl = TREE_VALUE (tuple);
+
+         parm_decl = tsubst (parm_decl, args, complain, NULL_TREE);
+         default_value = tsubst_expr (default_value, args,
+                                      complain, NULL_TREE);
+         tuple = build_tree_list (maybe_fold_nontype_arg (default_value), 
+                                  parm_decl);
+         TREE_VEC_ELT (new_vec, i) = tuple;
        }
       
       *new_parms = 
@@ -5909,6 +5909,9 @@ tsubst_decl (t, args, type)
     case PARM_DECL:
       {
        r = copy_node (t);
+       if (DECL_TEMPLATE_PARM_P (t))
+         SET_DECL_TEMPLATE_PARM_P (r);
+       
        TREE_TYPE (r) = type;
        c_apply_type_quals_to_decl (cp_type_quals (type), r);
 
@@ -5919,7 +5922,7 @@ tsubst_decl (t, args, type)
                                     /*complain=*/1, in_decl);
 
        DECL_CONTEXT (r) = NULL_TREE;
-       if (PROMOTE_PROTOTYPES
+       if (!DECL_TEMPLATE_PARM_P (r) && PROMOTE_PROTOTYPES
            && INTEGRAL_TYPE_P (type)
            && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
          DECL_ARG_TYPE (r) = integer_type_node;
index dac37bd7936f19826d38ba3feb00d9cc8aacea29..d08a707d18efb958dbefcfa338701680f09a18bd 100644 (file)
@@ -1,5 +1,7 @@
 2002-01-02  Nathan Sidwell  <nathan@codesourcery.com>
 
+       * g++.dg/template/ntp.C: New test.
+
        * g++.dg/other/component1.C: New test.
 
        * g++.dg/template/ttp3.C: New test.
diff --git a/gcc/testsuite/g++.dg/template/ntp1.C b/gcc/testsuite/g++.dg/template/ntp1.C
new file mode 100644 (file)
index 0000000..98698e9
--- /dev/null
@@ -0,0 +1,24 @@
+// { dg-do compile }
+
+// Copyright (C) 2001 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 26 Dec 2001 <nathan@codesourcery.com>
+
+// PR 35. We were default promoting template PARM_DECLs
+
+template <short B> class R {};
+
+template <class T> class A
+{
+  public:
+  template <short B>
+  void operator() (R<B> const &);
+};
+
+int main() {
+  A<int> a;
+  R<1> r;
+
+  a (r);
+  
+  return 0;
+}
This page took 0.096113 seconds and 5 git commands to generate.