C++17 class deduction issues
authorJason Merrill <jason@redhat.com>
Mon, 10 Oct 2016 20:48:51 +0000 (16:48 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 10 Oct 2016 20:48:51 +0000 (16:48 -0400)
PR c++/77890
PR c++/77912
* pt.c (do_class_deduction): Set cp_unevaluated_operand.
(tsubst) [TEMPLATE_TYPE_PARM]: Copy CLASS_PLACEHOLDER_TEMPLATE.

From-SVN: r240948

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

index 02adc2b5bf8490222ef2a07e28a5ef725eee8d3f..ff0435e62eaa840093f68e8674074b28b0dc1a2e 100644 (file)
@@ -1,3 +1,10 @@
+2016-10-10  Jason Merrill  <jason@redhat.com>
+
+       PR c++/77890
+       PR c++/77912
+       * pt.c (do_class_deduction): Set cp_unevaluated_operand.
+       (tsubst) [TEMPLATE_TYPE_PARM]: Copy CLASS_PLACEHOLDER_TEMPLATE.
+
 2016-10-08  Jason Merrill  <jason@redhat.com>
 
        * cp-gimplify.c (cp_fold): Add variable name.
index f6cd3ea47ba0bffd23886c468e937b28a98594f9..28b1c987153e696fa8012de09cf8f18c233d5d1e 100644 (file)
@@ -13233,11 +13233,15 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
                TYPE_POINTER_TO (r) = NULL_TREE;
                TYPE_REFERENCE_TO (r) = NULL_TREE;
 
-               /* Propagate constraints on placeholders.  */
                 if (TREE_CODE (t) == TEMPLATE_TYPE_PARM)
-                  if (tree constr = PLACEHOLDER_TYPE_CONSTRAINTS (t))
-                   PLACEHOLDER_TYPE_CONSTRAINTS (r)
-                     = tsubst_constraint (constr, args, complain, in_decl);
+                 {
+                   /* Propagate constraints on placeholders.  */
+                   if (tree constr = PLACEHOLDER_TYPE_CONSTRAINTS (t))
+                     PLACEHOLDER_TYPE_CONSTRAINTS (r)
+                       = tsubst_constraint (constr, args, complain, in_decl);
+                   else if (tree pl = CLASS_PLACEHOLDER_TEMPLATE (t))
+                     CLASS_PLACEHOLDER_TEMPLATE (r) = pl;
+                 }
 
                if (TREE_CODE (r) == TEMPLATE_TEMPLATE_PARM)
                  /* We have reduced the level of the template
@@ -24431,9 +24435,10 @@ do_class_deduction (tree tmpl, tree init, tsubst_flags_t complain)
       return error_mark_node;
     }
 
+  ++cp_unevaluated_operand;
   tree t = build_new_function_call (cands, &args, /*koenig*/false,
                                    complain|tf_decltype);
-
+  --cp_unevaluated_operand;
   release_tree_vector (args);
 
   return TREE_TYPE (t);
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction19.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction19.C
new file mode 100644 (file)
index 0000000..38327d1
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/77912
+// { dg-options -std=c++1z }
+
+template<class T> struct S{S(T){}}; 
+
+//error: invalid use of template type parameter 'S'
+template<class T> auto f(T t){return S(t);}
+
+int main()
+{
+  //fails
+  f(42);
+
+  //fails
+  //error: invalid use of template type parameter 'S'
+  [](auto a){return S(a);}(42); 
+
+  //works
+  [](int a){return S(a);}(42);
+}
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction20.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction20.C
new file mode 100644 (file)
index 0000000..58e8f7d
--- /dev/null
@@ -0,0 +1,21 @@
+// PR c++/77890
+// { dg-options -std=c++1z }
+
+template<class F> struct S{S(F&&f){}}; 
+void f()
+{
+  S([]{});
+}
+
+template <typename TF>
+struct scope_guard : TF
+{
+    scope_guard(TF f) : TF{f} { }
+    ~scope_guard() { (*this)(); }
+};
+
+void g() 
+{
+    struct K { void operator()() {} };
+    scope_guard _{K{}};
+}