PR c++/81525 - broken handling of auto in generic lambda.

* pt.c (tsubst_decl) [VAR_DECL]: Use strip_innermost_template_args.

From-SVN: r253415
This commit is contained in:
Jason Merrill 2017-10-04 11:38:24 -04:00 committed by Jason Merrill
parent b33d945ba8
commit 3d2be6b44d
3 changed files with 35 additions and 9 deletions

View File

@ -1,3 +1,8 @@
2017-10-04 Jason Merrill <jason@redhat.com>
PR c++/81525 - broken handling of auto in generic lambda.
* pt.c (tsubst_decl) [VAR_DECL]: Use strip_innermost_template_args.
2017-09-22 Eric Botcazou <ebotcazou@adacore.com>
PR bootstrap/81926

View File

@ -12896,15 +12896,17 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
&& VAR_HAD_UNKNOWN_BOUND (t)
&& type != error_mark_node)
type = strip_array_domain (type);
tree auto_node = type_uses_auto (type);
int len = TREE_VEC_LENGTH (args);
if (auto_node)
/* Mask off any template args past the variable's context so we
don't replace the auto with an unrelated argument. */
TREE_VEC_LENGTH (args) = TEMPLATE_TYPE_LEVEL (auto_node) - 1;
type = tsubst (type, args, complain, in_decl);
if (auto_node)
TREE_VEC_LENGTH (args) = len;
tree sub_args = args;
if (tree auto_node = type_uses_auto (type))
{
/* Mask off any template args past the variable's context so we
don't replace the auto with an unrelated argument. */
int nouter = TEMPLATE_TYPE_LEVEL (auto_node) - 1;
int extra = TMPL_ARGS_DEPTH (args) - nouter;
if (extra > 0)
sub_args = strip_innermost_template_args (args, extra);
}
type = tsubst (type, sub_args, complain, in_decl);
}
if (VAR_P (r))
{

View File

@ -0,0 +1,19 @@
// Related to c++/81525
// { dg-do compile { target c++14 } }
template <class X>
struct A
{
template <class T>
static void f()
{
[](auto b) {
auto c = +b;
}(42);
}
};
int main()
{
A<int>::f<int>();
}