From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 564AC3858D35; Thu, 6 Aug 2020 00:07:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 564AC3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596672467; bh=JPdmh31k043bnBklh0GaddDFezIpULyZON75exigPrM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XYjlzHIip/c8cb6Ok4tQ3QwKa82rmDUD2xoeQev9+Eti2A6gAJHFhJs3cyc34ppQb hRvxcox3qbAoIuGwxAi0nPy+YknA0/YyupIKNpQpeJJVi8RB1ErIRxGjrg/0NZfJ0P hyry5id+i9ic07r3Kh1rtLyFAXFS/zqxkuI1KaDc= From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/96468] Warn when an empty while loop could have been a do-while Date: Thu, 06 Aug 2020 00:07:47 +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.2.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: NEW 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: component 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 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: Thu, 06 Aug 2020 00:07:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96468 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Component|tree-optimization |c --- Comment #6 from Martin Sebor --- Oh. So you're just looking for a simple lexical check to see if a while statement is preceded by a block { } and a warning if it is and (presumably) isn't the result of macro expansion. E.g., issue a warning here: void f (void) { { debug ("in f ()"); } while (!signaled); // warn } but not here (: void f (void) { DEBUG // expands to { debug (...); } while (!signaled); // don't warn } That should be simpler and doable in the front end (so back to C for compon= ent) but also seems considerably less useful to me as well as more prone to nois= e.=20 Front end isn't really my area so I don't expect to work on this but a coup= le of questions occur to me: should blank lines between the closing curly or t= he while have any effect on the warnig? If yes as I would expect it starts to feel like it's in the same area as -Wmisleading-indentation. What about ot= her iteration statements -- should those be considered as well? while (condition); // warning? (spurious semicolon) { } for (...; condition; ...); // ditto { }=