]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
pt.c (maybe_fold_nontype_arg): Use TREE_TYPE of ARG as the criterion to avoid rebuild...
authorKriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
Sat, 11 Aug 2001 12:21:17 +0000 (12:21 +0000)
committerKriang Lerdsuwanakij <lerdsuwa@gcc.gnu.org>
Sat, 11 Aug 2001 12:21:17 +0000 (12:21 +0000)
* pt.c (maybe_fold_nontype_arg): Use TREE_TYPE of ARG as the
criterion to avoid rebuilding expression tree instead of
processing_template_decl.

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

From-SVN: r44793

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

index 5f62396a07c0be5b6ed0b5629845f298ec8b766d..29894a3a3fcc14c16b593a6262628735d9a2c1bc 100644 (file)
@@ -1,3 +1,9 @@
+2001-08-11  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       * pt.c (maybe_fold_nontype_arg): Use TREE_TYPE of ARG as the
+       criterion to avoid rebuilding expression tree instead of
+       processing_template_decl.
+
 2001-08-07  Jason Merrill  <jason_merrill@redhat.com>
 
        Support named return value optimization for inlines, too.
index 1f40089a4b59a3a7fabeed2e83bc8b93c5098919..853fd81764367d37146b428b8aac3b604c33391a 100644 (file)
@@ -5280,12 +5280,7 @@ static tree
 maybe_fold_nontype_arg (arg)
      tree arg;
 {
-  /* If we're not in a template, ARG is already as simple as it's going to
-     get, and trying to reprocess the trees will break.  */
-  if (! processing_template_decl)
-    return arg;
-
-  if (!TYPE_P (arg) && !uses_template_parms (arg))
+  if (arg && !TYPE_P (arg) && !uses_template_parms (arg))
     {
       /* Sometimes, one of the args was an expression involving a
         template constant parameter, like N - 1.  Now that we've
@@ -5295,10 +5290,18 @@ maybe_fold_nontype_arg (arg)
         fool build_expr_from_tree() into building an actual
         tree.  */
 
-      int saved_processing_template_decl = processing_template_decl; 
-      processing_template_decl = 0;
-      arg = fold (build_expr_from_tree (arg));
-      processing_template_decl = saved_processing_template_decl; 
+      /* 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.  */
+      if (!TREE_TYPE (arg))
+       {
+         int saved_processing_template_decl = processing_template_decl; 
+         processing_template_decl = 0;
+         arg = build_expr_from_tree (arg);
+         processing_template_decl = saved_processing_template_decl; 
+       }
+
+      arg = fold (arg);
     }
   return arg;
 }
index c5058bd70d5bcf0d326d5222bdb4578b5910078b..c360084b36bff390fb54c56e603a8263ac95448f 100644 (file)
@@ -1,3 +1,7 @@
+2001-08-11  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       * g++.dg/template/unify1.C: New test.
+
 2001-08-07  Nathan Sidwell  <nathan@codesourcery.com>
 
        * g++.dg/abi/empty4.C: New test.
diff --git a/gcc/testsuite/g++.dg/template/unify1.C b/gcc/testsuite/g++.dg/template/unify1.C
new file mode 100644 (file)
index 0000000..2f0a18c
--- /dev/null
@@ -0,0 +1,26 @@
+// Test non-type template argument folding.
+// Origin: smacdonald@seimac.com
+
+// { dg-do compile }
+
+template < int I1, int I2 >
+class unit
+{
+public:
+  unit() {}
+  unit( const unit<I1,I2>& ) {}
+  template< int Q1, int Q2 >
+  unit< I1 - Q1, I2 - Q2 > operator / ( const unit< Q1, Q2 >& rhs ) const {
+    return unit< I1 - Q1, I2 - Q2 >();
+  }
+};
+int main()
+{
+  const unit<1,0> u1;
+  const unit<2,0> u2;
+  unit<-1,0> u3( u1 / u2 );
+}