===================================================================
@@ -872,8 +872,10 @@ maybe_add_lambda_conv_op (tree type)
bool nested = (cfun != NULL);
bool nested_def = decl_function_context (TYPE_MAIN_DECL (type));
tree callop = lambda_function (type);
+ tree lam = CLASSTYPE_LAMBDA_EXPR (type);
- if (LAMBDA_EXPR_CAPTURE_LIST (CLASSTYPE_LAMBDA_EXPR (type)) != NULL_TREE)
+ if (LAMBDA_EXPR_CAPTURE_LIST (lam) != NULL_TREE
+ || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) != CPLD_NONE)
return;
if (processing_template_decl)
===================================================================
@@ -0,0 +1,10 @@
+// PR c++/71105
+// { dg-do compile { target c++11 } }
+
+void foo()
+{
+ int i;
+ static_cast<void(*)()>([i]{}); // { dg-error "invalid static_cast" }
+ static_cast<void(*)()>([=]{}); // { dg-error "invalid static_cast" }
+ static_cast<void(*)()>([&]{}); // { dg-error "invalid static_cast" }
+}
===================================================================
@@ -0,0 +1,13 @@
+// PR c++/71105
+// { dg-do compile { target c++14 } }
+
+void foo()
+{
+ int i;
+ static_cast<void(*)(int)>([i](auto){}); // { dg-error "invalid static_cast" }
+ static_cast<void(*)(int)>([=](auto){}); // { dg-error "invalid static_cast" }
+ static_cast<void(*)(int)>([&](auto){}); // { dg-error "invalid static_cast" }
+ static_cast<float(*)(float)>([i](auto x){ return x; }); // { dg-error "invalid static_cast" }
+ static_cast<float(*)(float)>([=](auto x){ return x; }); // { dg-error "invalid static_cast" }
+ static_cast<float(*)(float)>([&](auto x){ return x; }); // { dg-error "invalid static_cast" }
+}