diff options
Diffstat (limited to 'gcc/cp/pt.c')
-rw-r--r-- | gcc/cp/pt.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index dec7d39..022ffda 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -17142,19 +17142,34 @@ tsubst_copy_and_build (tree t, if (unq != function) { - tree fn = unq; - if (INDIRECT_REF_P (fn)) - fn = TREE_OPERAND (fn, 0); - if (TREE_CODE (fn) == COMPONENT_REF) - fn = TREE_OPERAND (fn, 1); - if (is_overloaded_fn (fn)) - fn = get_first_fn (fn); - if (permerror (EXPR_LOC_OR_LOC (t, input_location), - "%qD was not declared in this scope, " - "and no declarations were found by " - "argument-dependent lookup at the point " - "of instantiation", function)) + /* In a lambda fn, we have to be careful to not + introduce new this captures. Legacy code can't + be using lambdas anyway, so it's ok to be + stricter. */ + bool in_lambda = (current_class_type + && LAMBDA_TYPE_P (current_class_type)); + char const *msg = "%qD was not declared in this scope, " + "and no declarations were found by " + "argument-dependent lookup at the point " + "of instantiation"; + + bool diag = true; + if (in_lambda) + error_at (EXPR_LOC_OR_LOC (t, input_location), + msg, function); + else + diag = permerror (EXPR_LOC_OR_LOC (t, input_location), + msg, function); + if (diag) { + tree fn = unq; + if (INDIRECT_REF_P (fn)) + fn = TREE_OPERAND (fn, 0); + if (TREE_CODE (fn) == COMPONENT_REF) + fn = TREE_OPERAND (fn, 1); + if (is_overloaded_fn (fn)) + fn = get_first_fn (fn); + if (!DECL_P (fn)) /* Can't say anything more. */; else if (DECL_CLASS_SCOPE_P (fn)) @@ -17177,7 +17192,13 @@ tsubst_copy_and_build (tree t, inform (DECL_SOURCE_LOCATION (fn), "%qD declared here, later in the " "translation unit", fn); + if (in_lambda) + { + release_tree_vector (call_args); + RETURN (error_mark_node); + } } + function = unq; } } |