From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 70907385F033; Wed, 11 Aug 2021 09:19:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70907385F033 From: "tschwinge at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: tschwinge at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 09:19:00 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101862 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=3D51287&action=3Dedit '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 =3D 0; i < 32; i++) - assert (arr[i] =3D=3D ((i % 2) !=3D 0) ? i + 1 : i + 2); + assert (arr[i] =3D=3D (((i % 2) !=3D 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 abo= ut where/how to do this...)=