2019-02-21 Jason Merrill <jason@redhat.com>
+ PR c++/87685 - generic lambda 'this' capture error.
+ * lambda.c (lambda_expr_this_capture): Change add_capture_p to int.
+ (maybe_generic_this_capture): Pass -1.
+
PR c++/88394 - ICE with VLA init-capture.
* lambda.c (is_normal_capture_proxy): Check DECL_CAPTURED_VARIABLE.
extern bool is_normal_capture_proxy (tree);
extern bool is_constant_capture_proxy (tree);
extern void register_capture_members (tree);
-extern tree lambda_expr_this_capture (tree, bool);
+extern tree lambda_expr_this_capture (tree, int);
extern void maybe_generic_this_capture (tree, tree);
extern tree maybe_resolve_dummy (tree, bool);
extern tree current_nonlambda_function (void);
/* Return the capture pertaining to a use of 'this' in LAMBDA, in the
form of an INDIRECT_REF, possibly adding it through default
- capturing, if ADD_CAPTURE_P is true. */
+ capturing, if ADD_CAPTURE_P is nonzero. If ADD_CAPTURE_P is negative,
+ try to capture but don't complain if we can't. */
tree
-lambda_expr_this_capture (tree lambda, bool add_capture_p)
+lambda_expr_this_capture (tree lambda, int add_capture_p)
{
tree result;
result = this_capture;
else if (!this_capture)
{
- if (add_capture_p)
+ if (add_capture_p == 1)
{
error ("%<this%> was not captured for this lambda function");
result = error_mark_node;
&& DECL_NONSTATIC_MEMBER_FUNCTION_P (*iter))
{
/* Found a non-static member. Capture this. */
- lambda_expr_this_capture (lam, true);
+ lambda_expr_this_capture (lam, /*maybe*/-1);
break;
}
}
--- /dev/null
+// PR c++/87685
+// { dg-do compile { target c++14 } }
+
+struct A
+{
+ template <typename T> static void f(T) {}
+ void f() {}
+
+ void foo()
+ {
+ [] (auto&& v) { A::f(v); }; // OK if parameter type is specified
+ }
+};