public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/96311] [8/9/10/11 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) Date: Thu, 11 Feb 2021 15:25:04 +0000 [thread overview] Message-ID: <bug-96311-4-d8SgTmqZJL@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-96311-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311 --- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- If I compare void foo () { constexpr int used = 0; [](auto unused) { return used; }; } void bar () { constexpr int used = 0; [](int unused) { return used; }; } then in bar mark_exp_read is called on used from check_return_expr -> convert_for_initialization -> convert_from_assignment -> perform_implicit_conversion_flags -> mark_rvalue_use -> mark_use -> mark_exp_read, but for the generic lambda check_return_expr takes the goto dependent; and doesn't mark anything. It is only marked during instantiation of the lambda, such as when (0) as added in between } and ; and in that case the warning is gone. More complete testcase: void foo () { constexpr int used = 0; [](auto unused) { return used; }; } void bar () { constexpr int used = 0; [](int unused) { return used; }; } void baz () { constexpr int used = 0; [](auto unused) { return used; } (0); } void qux () { constexpr int used = 0; [](auto unused) { return used + 1; }; } void corge () { constexpr int used = 0; [](auto unused) { return used + unused; }; } This shows that if the variable is used in some non-dependent expression as in qux (and not directly in return statement), it is marked already without instantiation, but when it is only used directly in return stmt or used in a dependent expression, it is marked only during instantiation of the lambda. Though, when the lambda isn't really instantiated, the variable is not really used, so not 100% sure the warning is unwanted.
next prev parent reply other threads:[~2021-02-11 15:25 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-07-24 15:36 [Bug c++/96311] New: " tilkax at gmail dot com 2020-07-27 7:11 ` [Bug c++/96311] " marxin at gcc dot gnu.org 2020-07-27 7:40 ` tilkax at gmail dot com 2020-07-27 10:09 ` [Bug c++/96311] [8/9/10/11 Regression] " jakub at gcc dot gnu.org 2020-07-27 10:17 ` jakub at gcc dot gnu.org 2021-02-11 15:25 ` jakub at gcc dot gnu.org [this message] 2021-03-10 17:29 ` hewillk at gmail dot com 2021-04-05 20:04 ` jason at gcc dot gnu.org 2021-04-05 21:27 ` cvs-commit at gcc dot gnu.org 2021-04-05 21:29 ` [Bug c++/96311] [8/9/10 " jason at gcc dot gnu.org 2021-05-14 9:53 ` [Bug c++/96311] [9/10 " jakub at gcc dot gnu.org 2021-05-20 21:35 ` cvs-commit at gcc dot gnu.org 2021-06-01 8:18 ` rguenth at gcc dot gnu.org 2022-05-13 17:41 ` [Bug c++/96311] [9 " cvs-commit at gcc dot gnu.org 2022-05-13 17:45 ` jason at gcc dot gnu.org
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=bug-96311-4-d8SgTmqZJL@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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).