diff mbox

C++ PATCH for CWG2233

Message ID CADzB+2n_kz2257gurVYy-xNaAfCud6D0yy0Wp0+M8BiCfnftDQ@mail.gmail.com
State New
Headers show

Commit Message

Jason Merrill Nov. 13, 2016, 6:49 a.m. UTC
In Core working group discussions today we were looking at this
testcase, which caused the compiler to ICE because it assumed that
once we had seen one default argument, all following parameters would
have them as well.  This is no longer true now that we allow a
parameter pack to follow default arguments.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 4c59e1a2f90e1aa6f381692e843164ad0543f53b
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Nov 12 14:37:33 2016 -0800

            CWG 2233 - default arg and parameter pack
    
            * typeck.c (convert_arguments): Handle default arg followed by none.
diff mbox

Patch

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 211696c..24ca1b5 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3835,6 +3835,10 @@  convert_arguments (tree typelist, vec<tree, va_gc> **values, tree fndecl,
 	{
 	  for (; typetail != void_list_node; ++i)
 	    {
+	      /* After DR777, with explicit template args we can end up with a
+		 default argument followed by no default argument.  */
+	      if (!TREE_PURPOSE (typetail))
+		break;
 	      tree parmval
 		= convert_default_arg (TREE_VALUE (typetail),
 				       TREE_PURPOSE (typetail),
@@ -3850,9 +3854,10 @@  convert_arguments (tree typelist, vec<tree, va_gc> **values, tree fndecl,
 		break;
 	    }
 	}
-      else
+
+      if (typetail && typetail != void_list_node)
 	{
-          if (complain & tf_error)
+	  if (complain & tf_error)
 	    error_args_num (input_location, fndecl, /*too_many_p=*/false);
 	  return -1;
 	}
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic169.C b/gcc/testsuite/g++.dg/cpp0x/variadic169.C
new file mode 100644
index 0000000..6858973
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic169.C
@@ -0,0 +1,9 @@ 
+// DR 2233
+// { dg-do compile { target c++11 } }
+
+template<typename ...T> void f(int n = 0, T ...t);
+
+int main()
+{
+  f<int>();			// { dg-error "too few arguments" }
+}