Commit 130ee9a9 by Jason Merrill Committed by Jason Merrill

re PR c++/69392 (G++ can't capture 'this' pointer to templated type using init-capture)

	PR c++/69392
	* lambda.c (lambda_capture_field_type): Handle 'this' specially
	for init-capture, too.

From-SVN: r232746
parent 44b6ab2b
2016-01-21 Jason Merrill <jason@redhat.com>
PR c++/69392
* lambda.c (lambda_capture_field_type): Handle 'this' specially
for init-capture, too.
PR c++/65687
* decl.c (type_is_deprecated): Don't look into a typedef.
......
......@@ -207,15 +207,8 @@ tree
lambda_capture_field_type (tree expr, bool explicit_init_p)
{
tree type;
if (explicit_init_p)
{
type = make_auto ();
type = do_auto_deduction (type, expr, type);
}
else
type = non_reference (unlowered_expr_type (expr));
if (type_dependent_expression_p (expr)
&& !is_this_parameter (tree_strip_nop_conversions (expr)))
bool is_this = is_this_parameter (tree_strip_nop_conversions (expr));
if (!is_this && type_dependent_expression_p (expr))
{
type = cxx_make_type (DECLTYPE_TYPE);
DECLTYPE_TYPE_EXPR (type) = expr;
......@@ -223,6 +216,13 @@ lambda_capture_field_type (tree expr, bool explicit_init_p)
DECLTYPE_FOR_INIT_CAPTURE (type) = explicit_init_p;
SET_TYPE_STRUCTURAL_EQUALITY (type);
}
else if (!is_this && explicit_init_p)
{
type = make_auto ();
type = do_auto_deduction (type, expr, type);
}
else
type = non_reference (unlowered_expr_type (expr));
return type;
}
......
// PR c++/69392
// { dg-do compile { target c++14 } }
template <typename T>
class Foo {
public:
void foo(void) {}
auto getCallableFoo(void) {
return
[ptr = this]() { ptr->foo(); };
}
};
int main()
{
Foo<int> f;
auto callable = f.getCallableFoo();
callable();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment