PR c++/61636
        * g++.dg/cpp1y/pr61636.C: New test.
---
 gcc/cp/parser.c                      | 16 ++++++++++++++++
 gcc/testsuite/g++.dg/cpp1y/pr61636.C | 19 +++++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr61636.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 4d6b479..ac91976 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -6321,6 +6321,22 @@ cp_parser_postfix_expression (cp_parser *parser, bool 
address_p, bool cast_p,
                tree instance = TREE_OPERAND (postfix_expression, 0);
                tree fn = TREE_OPERAND (postfix_expression, 1);
 
+               /* For generic lambdas, resolve default captured 'this' now.  */
+               if (processing_template_decl
+                   && is_dummy_object (instance)
+                   && current_class_type
+                   && CLASSTYPE_LAMBDA_EXPR (current_class_type))
+                 if (tree callop = lambda_function (current_class_type))
+                   if (DECL_TEMPLATE_INFO (callop)
+                       && (DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (callop))
+                           == callop)
+                       && TREE_TYPE (instance) != current_class_type
+                       && DERIVED_FROM_P (TREE_TYPE (instance),
+                                          current_nonlambda_class_type ()))
+                     TREE_OPERAND (postfix_expression, 0)
+                       = instance
+                       = maybe_resolve_dummy (instance, true);
+
                if (processing_template_decl
                    && (type_dependent_expression_p (instance)
                        || (!BASELINK_P (fn)
diff --git a/gcc/testsuite/g++.dg/cpp1y/pr61636.C 
b/gcc/testsuite/g++.dg/cpp1y/pr61636.C
new file mode 100644
index 0000000..5694675
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/pr61636.C
@@ -0,0 +1,19 @@
+// PR c++/61636
+// { dg-do compile { target c++1y } }
+
+struct X
+{
+   void f(int) {}
+
+   auto defer_f()
+   {
+      return [&] (auto x) {
+         return f(x);
+      };
+   }
+};
+
+int main()
+{
+   X().defer_f()(2);
+}
-- 
2.3.5

Reply via email to