diff options
Diffstat (limited to 'gcc/cp/lambda.cc')
-rw-r--r-- | gcc/cp/lambda.cc | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index 4cc3a47f9c2..65579edc316 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -183,6 +183,24 @@ lambda_function (tree lambda) return lambda; } +/* True if EXPR is an expression whose type can be used directly in lambda + capture. Not to be used for 'auto'. */ + +static bool +type_deducible_expression_p (tree expr) +{ + if (!type_dependent_expression_p (expr)) + return true; + if (BRACE_ENCLOSED_INITIALIZER_P (expr) + || TREE_CODE (expr) == EXPR_PACK_EXPANSION) + return false; + tree t = non_reference (TREE_TYPE (expr)); + if (!t) return false; + while (TREE_CODE (t) == POINTER_TYPE) + t = TREE_TYPE (t); + return currently_open_class (t); +} + /* Returns the type to use for the FIELD_DECL corresponding to the capture of EXPR. EXPLICIT_INIT_P indicates whether this is a C++14 init capture, and BY_REFERENCE_P indicates whether we're @@ -211,7 +229,7 @@ lambda_capture_field_type (tree expr, bool explicit_init_p, else type = do_auto_deduction (type, expr, auto_node); } - else if (type_dependent_expression_p (expr)) + else if (!type_deducible_expression_p (expr)) { type = cxx_make_type (DECLTYPE_TYPE); DECLTYPE_TYPE_EXPR (type) = expr; @@ -741,6 +759,7 @@ lambda_expr_this_capture (tree lambda, int add_capture_p) { tree lambda_stack = NULL_TREE; tree init = NULL_TREE; + bool saw_complete = false; /* If we are in a lambda function, we can move out until we hit: 1. a non-lambda function or NSDMI, @@ -759,6 +778,11 @@ lambda_expr_this_capture (tree lambda, int add_capture_p) lambda_stack); tree closure = LAMBDA_EXPR_CLOSURE (tlambda); + if (COMPLETE_TYPE_P (closure)) + /* We're instantiating a generic lambda op(), the containing + scope may be gone. */ + saw_complete = true; + tree containing_function = decl_function_context (TYPE_NAME (closure)); @@ -768,7 +792,7 @@ lambda_expr_this_capture (tree lambda, int add_capture_p) /* Lambda in an NSDMI. We don't have a function to look up 'this' in, but we can find (or rebuild) the fake one from inject_this_parameter. */ - if (!containing_function && !COMPLETE_TYPE_P (closure)) + if (!containing_function && !saw_complete) /* If we're parsing a lambda in a non-local class, we can find the fake 'this' in scope_chain. */ init = scope_chain->x_current_class_ptr; |