Commit a4b4b1e3 by Jason Merrill

c++: Fix return deduction of lambda in discarded stmt.

A return statement in a discarded statement is not used for return type
deduction, but we still want to do deduction for a return statement in a
lambda in a discarded statement.

	PR c++/93442
	* parser.c (cp_parser_lambda_expression): Clear in_discarded_stmt.
parent 25d62480
2020-01-28 Jason Merrill <jason@redhat.com>
PR c++/93442
* parser.c (cp_parser_lambda_expression): Clear in_discarded_stmt.
PR c++/93477
PR c++/91476
* decl2.c (copy_linkage): Do copy DECL_ONE_ONLY and DECL_WEAK.
......
......@@ -10530,6 +10530,10 @@ cp_parser_lambda_expression (cp_parser* parser)
parser->implicit_template_scope = 0;
parser->auto_is_implicit_function_template_parm_p = false;
/* The body of a lambda in a discarded statement is not discarded. */
bool discarded = in_discarded_stmt;
in_discarded_stmt = 0;
/* By virtue of defining a local class, a lambda expression has access to
the private variables of enclosing classes. */
......@@ -10560,6 +10564,8 @@ cp_parser_lambda_expression (cp_parser* parser)
finish_struct (type, /*attributes=*/NULL_TREE);
in_discarded_stmt = discarded;
parser->num_template_parameter_lists = saved_num_template_parameter_lists;
parser->in_statement = in_statement;
parser->in_switch_statement_p = in_switch_statement_p;
// PR c++/93442
// { dg-do compile { target c++17 } }
struct bar {
int foo(){return 0;}
};
int foobar() {
if constexpr(true) {
return 0;
} else {
return [](){
return bar{};
}().foo();
}
}
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