public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "gccbugbjorn at fahller dot se" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/96400] New: False positive on Wunused-but-set-variable for static constexpr var used in lambda Date: Fri, 31 Jul 2020 09:56:21 +0000 [thread overview] Message-ID: <bug-96400-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96400 Bug ID: 96400 Summary: False positive on Wunused-but-set-variable for static constexpr var used in lambda Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gccbugbjorn at fahller dot se Target Milestone: --- Similar to Bug 96311, but not quite the same. This code is flags "is_zero" as being unused but set: template <typename Pred, typename Val> bool test(Pred p, Val v) { return p(v); } bool func(int* p) { static constexpr auto is_zero = [](auto v) { return v == 0;}; return test([](auto v){return is_zero(*v);}, p); } Output: <source>: In function 'bool func(int*)': <source>:9:27: warning: variable 'is_zero' set but not used [-Wunused-but-set-variable] 9 | static constexpr auto is_zero = [](auto v) { return v == 0;}; | ^~~~~~~ "is_zero" can correctly be used in the lambda without being captured, since it's static. The warning only appears when using the extra indirection "test()". Calling the anonymous lambda directly, without the indirection "test()", does not display the warning. Possibly "constexpr" is a red herring above. Godbolt link: https://godbolt.org/z/x4zb3s
next reply other threads:[~2020-07-31 9:56 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-07-31 9:56 gccbugbjorn at fahller dot se [this message] 2021-07-27 4:49 ` [Bug c++/96400] " pinskia at gcc dot gnu.org 2022-09-23 16:16 ` pinskia at gcc dot gnu.org 2022-09-23 16:27 ` pinskia 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-96400-4@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).