diff mbox

C++ PATCH for C++17 class deduction from empty initializer

Message ID CADzB+2nFTg78cPM9OP49fUDN1Ctm+5aOYCS91gjrRvo0CdPrTg@mail.gmail.com
State New
Headers show

Commit Message

Jason Merrill Feb. 22, 2017, 10:54 p.m. UTC
Someone on the C++ committee observed that

std::less l{};

didn't work in G++; this fixes that.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit d04e2de711e69266b24c118eb330100859b2671c
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Feb 21 16:50:29 2017 -0800

            * pt.c (do_class_deduction): Handle 0 argument case.
diff mbox

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 5b0f62d..17175ba 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -25126,6 +25126,14 @@  do_class_deduction (tree ptype, tree tmpl, tree init, int flags,
 
   if (cands == NULL_TREE)
     {
+      if (args->length() == 0)
+	{
+	  /* Try tmpl<>.  */
+	  tree t = lookup_template_class (tmpl, NULL_TREE, NULL_TREE,
+					  NULL_TREE, false, tf_none);
+	  if (t != error_mark_node)
+	    return t;
+	}
       error ("cannot deduce template arguments for %qT, as it has "
 	     "no deduction guides or user-declared constructors", type);
       return error_mark_node;
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction30.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction30.C
new file mode 100644
index 0000000..e182803
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction30.C
@@ -0,0 +1,6 @@ 
+// { dg-options -std=c++1z }
+
+template <class T = void> struct A { };
+
+A a{};
+