lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Sep 26, 2012 at 11:44:15AM -0600, William Sumner wrote:
> On Sep 26, 2012, at 11:34 AM, William Ahern <william@25thandClement.com> wrote:
<snip>
> > That's because clang and GCC are competing to add the most obnoxious
> > diagnostics, and the newest version of clang is usually a step or two ahead.
> > Just give it one or two releases, and GCC will fall into line.
> > 
> > Eventually they'll both just immediately exit with the diagnostic, "just use
> > C++ already if you want to cast so much", and then everybody's heads will
> > explode.
> > 
> 
> Is a default warning about a loss of integer precision that out of line?
> At any rate, adding explicit casts to my local copy of Lua's source
> resolves the issue.

It is when you're dealing with unsigned integers and the warning is by
default, or with the very common -Wall (as opposed to -Wextra). It becomes
extremely annoying when you're doing bit logic or modulo arithmetic. Integer
conversion to unsigned--even narrowing conversions--are always well defined
in C. Not only are they well defined, they're quite common and people depend
on the semantics.

More importantly, casting is evil. Once you cast, you'll never get another
diagnostic unless the conversion is totally fubar, like trying to cast to a
compound type. Casting in C is a trap door. Once you cast you lose the
benefit of most of the useful diagnostics.

Therefore, annoying diagnostics which cause unnecessary casting are a bad
thing. People will invariably begin to cast too much (including in the
immediate case that spurred the cast) because most people equate good code
with code that keeps the compiler quiet.

clang complains too much about about well defined code. The one I personally
dislike the most is -Winitializer-overrides, which complains about something
which the standard quite clearly and intentionally allows--because it's
useful. GCC puts that warning in -Wextra, where a lot of clang's warnings
should also go.