From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3950B3858D35; Tue, 16 Apr 2024 06:27:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3950B3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713248859; bh=s37PRJmbZMFhKvQooyyy4FgsAv62T/xLo7+NM8pPITQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gC0J26X2Exs+07kPyR27qLuOse92X7VStGqBR1/QXg6G89CAfZuYYKVh0fM+hkMzZ 0ogkOMMCT/VQ4+qAVp112+4Wbrggs3qnG9upq1UGUF3J2/vwexolnj2JStc51mbllx mEb3sBJBSPcTzO9cWfyfGT4mFnqJD4WmxyRKM1c0= From: "Hi-Angel at yandex dot ru" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/97100] -Wformat checks all arms of _Generic leading to irrelevant type expectation warnings Date: Tue, 16 Apr 2024 06:27:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: diagnostic, patch X-Bugzilla-Severity: normal X-Bugzilla-Who: Hi-Angel at yandex dot ru X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 14.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97100 --- Comment #10 from Konstantin Kharlamov --- (In reply to uecker from comment #9) > Some warnings are then even required to be standard compliant. I just searched through the C standard and no warnings seem to be required = by it. The only place where word "warning" is mentioned is in the Annex =E2=85= =A0, which tilted as "informative" and only serves as an example of where warnings mig= ht be useful. > x is - according to the C standard - always whatever it is in the control= ling > expression. With the prev. paragraph in mind, compiler is free to warn or not to about anything. The only (arguable) limitation is being useful. So nothing holds a compiler off from considering for the warning purposes the `x` to have different types on the outside of _Generic() compared to the inside. > Note that this also does not have to be an identifier, but could be a com= plex > expression. So there seems no simply algorithm for a compiler to do the r= ight thing > in general regarding warnings. Idk why complexity matters, it's not like `x` is dynamically typed, so no solving halting problem requried. For me it looks simple: if `x` entered ei= ther branch of _Generic, just consider it to have a type different from what it = was and produce correct warnings =F0=9F=98=8A=