Commit 4cda703e by Jason Merrill Committed by Jason Merrill

PR c++/85764 - bogus 'this' not captured error.

	* lambda.c (resolvable_dummy_lambda): Use nonlambda_method_basetype.
	(nonlambda_method_basetype): Handle NSDMI.

From-SVN: r261101
parent 946d79a6
2018-06-01 Jason Merrill <jason@redhat.com> 2018-06-01 Jason Merrill <jason@redhat.com>
PR c++/85764 - bogus 'this' not captured error.
* lambda.c (resolvable_dummy_lambda): Use nonlambda_method_basetype.
(nonlambda_method_basetype): Handle NSDMI.
CWG 1581: When are constexpr member functions defined? CWG 1581: When are constexpr member functions defined?
* constexpr.c (instantiate_cx_fn_r, instantiate_constexpr_fns): New. * constexpr.c (instantiate_cx_fn_r, instantiate_constexpr_fns): New.
(cxx_eval_outermost_constant_expr): Call instantiate_constexpr_fns. (cxx_eval_outermost_constant_expr): Call instantiate_constexpr_fns.
......
...@@ -884,7 +884,7 @@ resolvable_dummy_lambda (tree object) ...@@ -884,7 +884,7 @@ resolvable_dummy_lambda (tree object)
&& current_class_type && current_class_type
&& LAMBDA_TYPE_P (current_class_type) && LAMBDA_TYPE_P (current_class_type)
&& lambda_function (current_class_type) && lambda_function (current_class_type)
&& DERIVED_FROM_P (type, current_nonlambda_class_type ())) && DERIVED_FROM_P (type, nonlambda_method_basetype()))
return CLASSTYPE_LAMBDA_EXPR (current_class_type); return CLASSTYPE_LAMBDA_EXPR (current_class_type);
return NULL_TREE; return NULL_TREE;
...@@ -949,30 +949,37 @@ current_nonlambda_function (void) ...@@ -949,30 +949,37 @@ current_nonlambda_function (void)
return fn; return fn;
} }
/* Returns the method basetype of the innermost non-lambda function, or /* Returns the method basetype of the innermost non-lambda function, including
NULL_TREE if none. */ a hypothetical constructor if inside an NSDMI, or NULL_TREE if none. */
tree tree
nonlambda_method_basetype (void) nonlambda_method_basetype (void)
{ {
tree fn, type;
if (!current_class_ref) if (!current_class_ref)
return NULL_TREE; return NULL_TREE;
type = current_class_type; tree type = current_class_type;
if (!type || !LAMBDA_TYPE_P (type)) if (!type || !LAMBDA_TYPE_P (type))
return type; return type;
/* Find the nearest enclosing non-lambda function. */ while (true)
fn = TYPE_NAME (type); {
do tree lam = CLASSTYPE_LAMBDA_EXPR (type);
fn = decl_function_context (fn); tree ex = LAMBDA_EXPR_EXTRA_SCOPE (lam);
while (fn && LAMBDA_FUNCTION_P (fn)); if (ex && TREE_CODE (ex) == FIELD_DECL)
/* Lambda in an NSDMI. */
if (!fn || !DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)) return DECL_CONTEXT (ex);
return NULL_TREE;
tree fn = TYPE_CONTEXT (type);
return TYPE_METHOD_BASETYPE (TREE_TYPE (fn)); if (!fn || TREE_CODE (fn) != FUNCTION_DECL
|| !DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
/* No enclosing non-lambda method. */
return NULL_TREE;
if (!LAMBDA_FUNCTION_P (fn))
/* Found an enclosing non-lambda method. */
return TYPE_METHOD_BASETYPE (TREE_TYPE (fn));
type = DECL_CONTEXT (fn);
}
} }
/* Like current_scope, but looking through lambdas. */ /* Like current_scope, but looking through lambdas. */
......
// PR c++/85764
// { dg-do compile { target c++14 } }
template<typename Key>
class trie {
static void for_each(int & f, trie const & n, Key & prefix) {
[&](trie const & c) {
for_each(f, c, prefix);
};
}
void for_each(int & f) const {
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment