I think a warning shoul be raised when someone writes if (condition); { } instead of if (condition) { } (===== Watch at the ";" ====) Actually, it can only be a mistake, and that's a pity it's not detected. It drives to severe bugs. Release: 2.95 -> 3.4 Environment: DOS (DJGPP) How-To-Repeat: int x=1; if (x == 0); { cout << "x equals zero" << endl; }
Fix: int x=1; if (x == 0) { cout << "x equals zero" << endl; }
From: Carlo Wood <carlo@alinoe.com> To: jbach1@caramail.com Cc: gcc-gnats@gcc.gnu.org Subject: Re: preprocessor/5520: There's a warning I miss with "if{} else{}" statement Date: Tue, 29 Jan 2002 03:09:21 +0100 On Mon, Jan 28, 2002 at 11:41:20PM -0000, jbach1@caramail.com wrote: > I think a warning shoul be raised when someone writes > if (condition); Only *before* replacing macros please (if at all). Macros can be empty and be used like: if (condition) POSSIBLY_EMPTY_MACRO; -- Carlo Wood <carlo@alinoe.com>
State-Changed-From-To: open->analyzed State-Changed-Why: confirmed. gcc has such a warning. To address carlo's point. Macros that expand to noexpression, are usually written as '((void)0)'
Responsible-Changed-From-To: unassigned->gdr Responsible-Changed-Why: Diagnostic mantainer
http://gcc.gnu.org/ml/gcc-patches/2005-12/msg01627.html
*** Bug 19773 has been marked as a duplicate of this bug. ***
Subject: Re: Add a warning to detect empty body of if statements (like in the C frontend) mueller at kde dot org wrote: > ------- Comment #5 from mueller at kde dot org 2006-01-05 10:19 ------- > http://gcc.gnu.org/ml/gcc-patches/2005-12/msg01627.html Could cp_parser_implicitly_scoped_statement be flattened to use cp_lexer_next_token_is, rather than CLNTI_not? that'd read better. I'd suggest if(cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)) .. handle {...} else if (cp_lexer_next_token_is (parser->lexer (CPP_SEMICOLON)) .. handle empty else .. handle implicitly scoped stmt The C++ changes will be ok with that change. Someone else will need to approve the C change (but it looks ok to me) nathan
Created attachment 10596 [details] updated patch I agree, that makes it much more readable. updated accordingly and rediffed against current trunk. bootstrapped, regtested successfully.
Subject: Bug 5520 Author: rguenth Date: Fri Jan 20 09:30:22 2006 New Revision: 110019 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110019 Log: 2006-01-20 Dirk Mueller <dmueller@suse.com> PR c++/5520 * c-parser.c (c_parser_if_body): Use build_empty_stmt() instead of a special NOP marker. * c-typeck.c (c_finish_if_stmt): Remove obsoleted special NOP marker handling. * c-common.h (empty_body_warning): Add forward declaration. * c-common.c (empty_body_warning): Add (from c_finish_if_stmt). Now uses IS_EMPTY_STMT() instead of special NOP markers. * semantics.c (finish_if_stmt): Call empty_body_warning. * parser.c (cp_parser_implicitly_scoped_statement): Mark empty statement with an empty stmt. * g++.dg/warn/empty-body.C: New. Added: trunk/gcc/testsuite/g++.dg/warn/empty-body.C Modified: trunk/gcc/ChangeLog trunk/gcc/c-common.c trunk/gcc/c-common.h trunk/gcc/c-parser.c trunk/gcc/c-typeck.c trunk/gcc/cp/ChangeLog trunk/gcc/cp/parser.c trunk/gcc/cp/semantics.c trunk/gcc/testsuite/ChangeLog
Fixed.
*** Bug 28992 has been marked as a duplicate of this bug. ***