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]

[C++ PATCH] Fix ... handling in more_specialized_fn (PR c++/33962)


Hi!

If args1 and/or args2 are arguments of a function with ellipsis, then
len can be bigger than the number of arguments in the list.
The old more_specialized code would just stop when reaching
this, I don't see how can it deduce anything against ...

Regtested on x86_64-linux, ok for trunk?

2007-11-19  Jakub Jelinek  <jakub@redhat.com>

	PR c++/33962
	* pt.c (more_specialized_fn): Don't segfault if one or
	both argument list end with ellipsis.

	* g++.dg/overload/template3.C: New test.

--- gcc/cp/pt.c.jj	2007-11-19 09:48:36.000000000 +0100
+++ gcc/cp/pt.c	2007-11-19 12:00:31.000000000 +0100
@@ -13544,6 +13544,10 @@ more_specialized_fn (tree pat1, tree pat
 
       args1 = TREE_CHAIN (args1);
       args2 = TREE_CHAIN (args2);
+
+      /* Stop when an ellipsis is seen.  */
+      if (args1 == NULL_TREE || args2 == NULL_TREE)
+	break;
     }
 
   processing_template_decl--;
--- gcc/testsuite/g++.dg/overload/template3.C.jj	2007-11-19 12:02:23.000000000 +0100
+++ gcc/testsuite/g++.dg/overload/template3.C	2007-11-19 12:06:16.000000000 +0100
@@ -0,0 +1,15 @@
+// PR c++/33962
+// { dg-do compile }
+
+template <class T> struct A;
+
+template <class U> void foo (const U &x, ...);
+template <class T> void foo (const A<T> &x, ...);
+
+void bar (const A<int> &x, const char *y)
+{
+  foo (x, y);
+}
+
+/* { dg-final { scan-assembler "_Z3fooIiEvRK1AIT_Ez" } } */
+/* { dg-final { scan-assembler-not "_Z3fooI1AIiEEvRKT_z" } } */

	Jakub


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