public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/redhat/heads/gcc-10-branch)] c++: Fix return deduction of lambda in discarded stmt. Date: Thu, 30 Jan 2020 20:53:00 -0000 [thread overview] Message-ID: <20200130205252.81955.qmail@sourceware.org> (raw) https://gcc.gnu.org/g:a4b4b1e3ac9a2c97f7550024c3cc5aff52e0614c commit a4b4b1e3ac9a2c97f7550024c3cc5aff52e0614c Author: Jason Merrill <jason@redhat.com> Date: Tue Jan 28 16:06:33 2020 -0500 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. Diff: --- gcc/cp/ChangeLog | 3 +++ gcc/cp/parser.c | 6 ++++++ gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda1.C | 16 ++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0a959bb..9392c85 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 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. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 72037ee..b832782 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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; diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda1.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda1.C new file mode 100644 index 0000000..64c4cd2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda1.C @@ -0,0 +1,16 @@ +// 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(); + } +}
reply other threads:[~2020-01-30 20:53 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200130205252.81955.qmail@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).