OSDN Git Service

cp/
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 30 Nov 2009 22:45:06 +0000 (22:45 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 30 Nov 2009 22:45:06 +0000 (22:45 +0000)
2009-11-30  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/40371
* call.c (add_template_candidate_real): Early return NULL if
the arglist length is smaller than skip_without_in_chrg; tidy.

testsuite/
2009-11-30  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/40371
* g++.dg/template/crash93.C: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@154852 138bc75d-0d04-0410-961f-82ee72b054a4

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

index e035f3d..0be2491 100644 (file)
@@ -1,3 +1,9 @@
+2009-11-30  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/40371
+       * call.c (add_template_candidate_real): Early return NULL if
+       the arglist length is smaller than skip_without_in_chrg; tidy.
+
 2009-11-30  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/42069
index 70a5b1e..837a65d 100644 (file)
@@ -2457,9 +2457,10 @@ add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
 {
   int ntparms = DECL_NTPARMS (tmpl);
   tree targs = make_tree_vec (ntparms);
-  unsigned int nargs;
-  int skip_without_in_chrg;
-  tree first_arg_without_in_chrg;
+  unsigned int len = VEC_length (tree, arglist);
+  unsigned int nargs = (first_arg == NULL_TREE ? 0 : 1) + len;
+  unsigned int skip_without_in_chrg = 0;
+  tree first_arg_without_in_chrg = first_arg;
   tree *args_without_in_chrg;
   unsigned int nargs_without_in_chrg;
   unsigned int ia, ix;
@@ -2468,12 +2469,6 @@ add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
   int i;
   tree fn;
 
-  nargs = (first_arg == NULL_TREE ? 0 : 1) + VEC_length (tree, arglist);
-
-  skip_without_in_chrg = 0;
-
-  first_arg_without_in_chrg = first_arg;
-
   /* We don't do deduction on the in-charge parameter, the VTT
      parameter or 'this'.  */
   if (DECL_NONSTATIC_MEMBER_FUNCTION_P (tmpl))
@@ -2494,9 +2489,11 @@ add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
        ++skip_without_in_chrg;
     }
 
+  if (len < skip_without_in_chrg)
+    return NULL;
+
   nargs_without_in_chrg = ((first_arg_without_in_chrg != NULL_TREE ? 1 : 0)
-                          + (VEC_length (tree, arglist)
-                             - skip_without_in_chrg));
+                          + (len - skip_without_in_chrg));
   args_without_in_chrg = XALLOCAVEC (tree, nargs_without_in_chrg);
   ia = 0;
   if (first_arg_without_in_chrg != NULL_TREE)
index 5db13f2..a7d248f 100644 (file)
@@ -1,3 +1,8 @@
+2009-11-30  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/40371
+       * g++.dg/template/crash93.C: New.
+
 2009-11-30  Steve Ellcey  <sje@cup.hp.com>
 
        * gcc.dg/pr41551.c: New test.
diff --git a/gcc/testsuite/g++.dg/template/crash93.C b/gcc/testsuite/g++.dg/template/crash93.C
new file mode 100644 (file)
index 0000000..696a04a
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/40371
+
+struct A
+{
+  typedef void (&F)();
+  template<int> operator F();
+};
+
+void foo()
+{
+  A()(); // { dg-error "no match" }
+}