warn_unused_vars

Martin Bjorklund <>
Fri Sep 1 10:35:21 CEST 2006


Thomas Lindgren <> wrote:
> 
> 
> --- Richard Carlsson <> wrote:
> 
> > Robert Virding wrote:
> > > Actually this is simple way to get rid of the
> > annoying whining by the
> > > compiler, just prepend every variable with _ and
> > it keeps quiet. :-)
> > > 
> > > Seriously I would prefer the default to be to keep
> > quiet.
> > 
> > Seriously, that would be a bad idea. It catches
> > _way_ too many errors
> > (nasty, hard-to-find typo bugs) to be turned off by
> > default.
> > 
> > Oh, not in _your_ code, of course. Goes without
> > saying. ;-)
> 
> Not in my experience. I have it turned off in my
> makefiles and aren't having any problems worth
> mentioning. 

In my experience, this warning catches some real bugs.

As a completely arbitrarily, random, example, I'll give an example of
some real code from our xpath implementation:

eval_axis(attribute, NodeTest, _Preds, Ctx, S, F) ->
    case NodeTest of
        %% deleted code to make example smaller
	{namespace, NS} ->
	    Succ = namespace_test(NS, S),
	    ?ctx:attributes_of(Ctx, S, F);
	Other ->
	    ?xp_exit(unknown_node_test, Other)
    end;

Now, the compiler warns that the variable Succ is unused.  Is this a
bug?  Probably, b/c the attributes_of/3 function takes a "Succ" as
second parameter.


/martin



More information about the erlang-questions mailing list