public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-9846] c++: -Wunused, constant, and generic lambda [PR96311] Date: Thu, 20 May 2021 21:35:09 +0000 (GMT) [thread overview] Message-ID: <20210520213509.E4DB73987C30@sourceware.org> (raw) https://gcc.gnu.org/g:8909ed58700694f5ba66499739edfea90a0fc813 commit r10-9846-g8909ed58700694f5ba66499739edfea90a0fc813 Author: Jason Merrill <jason@redhat.com> Date: Mon Apr 5 16:22:51 2021 -0400 c++: -Wunused, constant, and generic lambda [PR96311] We never called mark_use for a return value in a function with dependent return type. In that situation we don't know if the use is as an rvalue or lvalue, but we can use mark_exp_read instead. gcc/cp/ChangeLog: PR c++/96311 * typeck.c (check_return_expr): Call mark_exp_read in dependent case. gcc/testsuite/ChangeLog: PR c++/96311 * g++.dg/cpp1y/lambda-generic-Wunused.C: New test. Diff: --- gcc/cp/typeck.c | 3 +++ gcc/testsuite/g++.dg/cpp1y/lambda-generic-Wunused.C | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 6ebf6319efd..a85a75c81ae 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -10037,6 +10037,9 @@ check_return_expr (tree retval, bool *no_warning) dependent: /* We should not have changed the return value. */ gcc_assert (retval == saved_retval); + /* We don't know if this is an lvalue or rvalue use, but + either way we can mark it as read. */ + mark_exp_read (retval); return retval; } diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-Wunused.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-Wunused.C new file mode 100644 index 00000000000..b43cbe6b675 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-Wunused.C @@ -0,0 +1,18 @@ +// PR c++/96311 +// { dg-do compile { target c++14 } } +// { dg-additional-options -Wunused } + +auto foo() +{ + constexpr int used = 0; + return + [](auto unused) + { + return used; + }; +} + +int main() +{ + foo()(42); +}
reply other threads:[~2021-05-20 21:35 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=20210520213509.E4DB73987C30@sourceware.org \ --to=jason@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).