This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH RFA: Add new warning for jump across initialized variable


On Wed, 10 Jun 2009, Ian Lance Taylor wrote:

> This patch adds a new warning to the C frontend: -Wgoto-misses-init.
> This warns about cases where a goto, or a switch, branches across the
> initialization of a variable.  For example:

Since this covers switch statements, I think an option name only 
mentioning goto is bad; -Wjump-misses-init or -Wjump-across-init would be 
better.  OK with that change and otherwise fixed as indicated below.

> +static void
> +check_earlier_gotos (tree label, struct c_label_vars* label_vars)
> +{
> +  unsigned int ix;
> +  struct c_goto_bindings* g;

Should have " *" not "* ".

> +/* This is called at the point of a case or default label to issue
> +   warnings about decls as needed.  It returns true if it found an
> +   error, not just a warning.  */
> +
> +bool
> +c_check_switch_goto_warnings (struct c_spot_bindings *switch_bindings,
> +			      location_t switch_loc, location_t case_loc)
> +{
[...]
> +  if (switch_bindings->stmt_exprs > 0)
> +    {
> +      error_at (case_loc, "switch jumps into statement expression");
> +      inform (switch_loc, "switch starts here");

This error case does not set saw_error; either it needs to do so, or the 
comment at the start of the function needs correcting.

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]