public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "tschwinge at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/101862] New: [C, C++] Potential '?:' diagnostic for always-true expressions in boolean context Date: Wed, 11 Aug 2021 09:19:00 +0000 [thread overview] Message-ID: <bug-101862-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101862 Bug ID: 101862 Summary: [C, C++] Potential '?:' diagnostic for always-true expressions in boolean context Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: tschwinge at gcc dot gnu.org Target Milestone: --- Created attachment 51287 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51287&action=edit 'c-c++-common/goacc/prN.c' Would it be possible for GCC to diagnose the "'?:' misuse" in the attached C/C++ test case? No matter what gets stored in 'arr', the 'assert' never triggers, because what's actually meant here, is: for (int i = 0; i < 32; i++) - assert (arr[i] == ((i % 2) != 0) ? i + 1 : i + 2); + assert (arr[i] == (((i % 2) != 0) ? i + 1 : i + 2)); This is going to be more complicated than 'gcc/c-family/c-common.c:c_common_truthvalue_conversion', 'case COND_EXPR:', which diagnoses "'?:' using integer constants in boolean context" for 'INTEGER_CST's -- which these are not, of course. I suppose we'd need some value range analysis (so, at some later stage in the pass pipeline?) to see that 'i + 1'/'i + 2' are always-true expressions in boolean context? Is this feasible or not? (..., and if yes, if anybody got any pointers about where/how to do this...)
next reply other threads:[~2021-08-11 9:19 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-11 9:19 tschwinge at gcc dot gnu.org [this message] 2021-08-11 17:42 ` [Bug middle-end/101862] " amacleod at redhat dot com 2021-08-13 5:25 ` egallager at gcc dot gnu.org 2021-08-16 10:22 ` tschwinge 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-101862-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).