Fwd: C++ PATCH for c++/77890, 77912 (C++17 class deduction issues)

Jason Merrill jason@redhat.com
Mon Oct 10 21:01:00 GMT 2016


77890: we were losing the CLASS_PLACEHOLDER_TEMPLATE when reducing the
level of a TEMPLATE_TYPE_PARM.

77912: after 77890 was fixed, we were complaining about an undefined
deduction guide; set cp_unevaluated_operand to prevent that.

Tested x86_64-pc-linux-gnu, applying to trunk.
-------------- next part --------------
commit 927a7c6142c7e08bdc37e94e776201f801de0df8
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Oct 10 13:52:50 2016 -0400

    C++17 class deduction issues
    
            PR c++/77890
            PR c++/77912
            * pt.c (do_class_deduction): Set cp_unevaluated_operand.
            (tsubst) [TEMPLATE_TYPE_PARM]: Copy CLASS_PLACEHOLDER_TEMPLATE.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index f6cd3ea..28b1c98 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -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
index 0000000..38327d1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction19.C
@@ -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
index 0000000..58e8f7d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction20.C
@@ -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{}};
+}


More information about the Gcc-patches mailing list