re PR c++/23789 (compilation error when template parameters have certain complexity)
authorMark Mitchell <mark@codesourcery.com>
Mon, 12 Sep 2005 22:38:34 +0000 (22:38 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Mon, 12 Sep 2005 22:38:34 +0000 (22:38 +0000)
PR c++/23789
* cvt.c (perform_qualification_conversions): Don't create
unnecessary NOP_EXPRs.
* pt.c (tsubst_template_arg): Use fold_non_dependent_expr.

PR c++/23789
* g++.dg/template/nontype14.C: New test.

From-SVN: r104193

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

index b0f70bc07dde72d23b2efb1db80d5dc1273b1495..6ce6f5fd1f78704b803530ca26e6f411363fdc84 100644 (file)
@@ -1,3 +1,10 @@
+2005-09-12  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/23789
+       * cvt.c (perform_qualification_conversions): Don't create
+       unnecessary NOP_EXPRs.
+       * pt.c (tsubst_template_arg): Use fold_non_dependent_expr.
+
 2005-09-12  Ian Lance Taylor  <ian@airs.com>
 
        PR g++/7874
index de0792aca47ef470b17076ea5576e1b95e66f5e4..ac24e0a5f34f6d1a40811ca689518cbfffdfbe95 100644 (file)
@@ -1209,8 +1209,10 @@ perform_qualification_conversions (tree type, tree expr)
 
   expr_type = TREE_TYPE (expr);
 
-  if (TYPE_PTR_P (type) && TYPE_PTR_P (expr_type)
-      && comp_ptr_ttypes (TREE_TYPE (type), TREE_TYPE (expr_type)))
+  if (same_type_p (type, expr_type))
+    return expr;
+  else if (TYPE_PTR_P (type) && TYPE_PTR_P (expr_type)
+          && comp_ptr_ttypes (TREE_TYPE (type), TREE_TYPE (expr_type)))
     return build_nop (type, expr);
   else if (TYPE_PTR_TO_MEMBER_P (type)
           && TYPE_PTR_TO_MEMBER_P (expr_type)
index 3f749554e675b85ceb8dd04c31ce5b78ead5d7c0..07054ecf314cbc492ea8b005abf37f43abc8a2ac 100644 (file)
@@ -5919,32 +5919,7 @@ tsubst_template_arg (tree t, tree args, tsubst_flags_t complain, tree in_decl)
   else
     {
       r = tsubst_expr (t, args, complain, in_decl);
-
-      if (!uses_template_parms (r))
-       {
-         /* Sometimes, one of the args was an expression involving a
-            template constant parameter, like N - 1.  Now that we've
-            tsubst'd, we might have something like 2 - 1.  This will
-            confuse lookup_template_class, so we do constant folding
-            here.  We have to unset processing_template_decl, to fool
-            tsubst_copy_and_build() into building an actual tree.  */
-
-        /* If the TREE_TYPE of ARG is not NULL_TREE, ARG is already
-           as simple as it's going to get, and trying to reprocess
-           the trees will break.  Once tsubst_expr et al DTRT for
-           non-dependent exprs, this code can go away, as the type
-           will always be set.  */
-         if (!TREE_TYPE (r))
-           {
-             int saved_processing_template_decl = processing_template_decl;
-             processing_template_decl = 0;
-             r = tsubst_copy_and_build (r, /*args=*/NULL_TREE,
-                                        tf_error, /*in_decl=*/NULL_TREE,
-                                        /*function_p=*/false);
-             processing_template_decl = saved_processing_template_decl;
-             r = fold (r);
-           }
-       }
+      r = fold_non_dependent_expr (r);
     }
   return r;
 }
index cdea80a8ccd37acba70604278cfd27de7be10c13..9678760d8a659c5ff1575eb48f05d345361f157f 100644 (file)
@@ -1,3 +1,8 @@
+2005-09-12  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/23789
+       * g++.dg/template/nontype14.C: New test.
+
 2005-09-12  Ian Lance Taylor  <ian@airs.com>
 
        PR g++/7874
diff --git a/gcc/testsuite/g++.dg/template/nontype14.C b/gcc/testsuite/g++.dg/template/nontype14.C
new file mode 100644 (file)
index 0000000..9333851
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/23789
+
+template <int W> struct X { 
+  template <int W2> 
+  X< (W+(W&&W) > 1 ? W+(W&&W) : 1)+1> 
+  operator + (const X<W2>&) const; 
+}; 
+template <int dummy> void foo() 
+{ 
+  X<6> A,B; 
+  A + B; 
+}