PR c++/88631 - CTAD failing for value-initialization.
authorMarek Polacek <polacek@redhat.com>
Wed, 2 Jan 2019 22:20:45 +0000 (22:20 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 2 Jan 2019 22:20:45 +0000 (22:20 +0000)
* typeck2.c (build_functional_cast): Try deducing the template
arguments even if there are no arguments to deduce from.

* g++.dg/cpp1z/class-deduction59.C: New test.

From-SVN: r267533

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1z/class-deduction59.C [new file with mode: 0644]

index fa03419c53ec7f87d86dba86507ad4bd9f0b7bc6..1ac5832d4554acc3b8c89c9cebd7ed155bb3f04d 100644 (file)
@@ -4,6 +4,10 @@
        * call.c (convert_for_arg_passing): Only give warnings with tf_warning.
        * typeck.c (convert_for_assignment): Likewise.
 
+       PR c++/88631 - CTAD failing for value-initialization.
+       * typeck2.c (build_functional_cast): Try deducing the template
+       arguments even if there are no arguments to deduce from.
+
 2019-01-01  Jakub Jelinek  <jakub@redhat.com>
 
        Update copyright years.
index 5dec117fb9e7c04bad6819aff53a861a4a6b7f61..03b24a94edee2608e0da0a252b21ef37fd2d8def 100644 (file)
@@ -2147,9 +2147,18 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
        }
       else if (!parms)
        {
-         if (complain & tf_error)
-           error ("cannot deduce template arguments for %qT from ()", anode);
-         return error_mark_node;
+         /* Even if there are no parameters, we might be able to deduce from
+            default template arguments.  Pass TF_NONE so that we don't
+            generate redundant diagnostics.  */
+         type = do_auto_deduction (type, parms, anode, tf_none,
+                                   adc_variable_type);
+         if (type == error_mark_node)
+           {
+             if (complain & tf_error)
+               error ("cannot deduce template arguments for %qT from ()",
+                      anode);
+             return error_mark_node;
+           }
        }
       else
        type = do_auto_deduction (type, parms, anode, complain,
index d2a214b3a1c77321a33f295bc1cf7c1c67963fd8..b4cf17811ab46873eebce620858f8c94181515f1 100644 (file)
@@ -3,6 +3,9 @@
        PR c++/88612 - ICE with -Waddress-of-packed-member.
        * g++.dg/warn/Waddress-of-packed-member1.C: New test.
 
+       PR c++/88631 - CTAD failing for value-initialization.
+       * g++.dg/cpp1z/class-deduction59.C: New test.
+
 2019-01-02  Martin Sebor  <msebor@redhat.com>
             Jeff Law  <law@redhat.com>
 
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction59.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction59.C
new file mode 100644 (file)
index 0000000..129d723
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/88631
+// { dg-do compile { target c++17 } }
+
+template<class T = void>
+class A { };
+
+int main()
+{
+  auto x = A();
+  auto x2 = A{};
+  A y;
+}