mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-27 05:44:15 +08:00
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. From-SVN: r240948
This commit is contained in:
parent
d30078b8e7
commit
b7beb16ac1
@ -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.
|
||||
|
15
gcc/cp/pt.c
15
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);
|
||||
|
20
gcc/testsuite/g++.dg/cpp1z/class-deduction19.C
Normal file
20
gcc/testsuite/g++.dg/cpp1z/class-deduction19.C
Normal file
@ -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);
|
||||
}
|
21
gcc/testsuite/g++.dg/cpp1z/class-deduction20.C
Normal file
21
gcc/testsuite/g++.dg/cpp1z/class-deduction20.C
Normal file
@ -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{}};
|
||||
}
|
Loading…
Reference in New Issue
Block a user