how to make gcc warn about arithmetic signed overflow

James K. Lowden jklowden@schemamania.org
Mon Sep 23 22:44:00 GMT 2013


On Mon, 23 Sep 2013 22:50:09 +0100
Jonathan Wakely <jwakely.gcc@gmail.com> wrote:

> On 23 September 2013 16:47, James K. Lowden wrote:
> >
> > 7.1.6 is itself mutable, it turns out.  My yellowed ARM, copyright
> > 1990, is considerably more relaxed on the question. (And
> > considerably easier to read.  I don't know how anyone learns C++
> > these days, so dense is the technical terminology.)
> 
> The standard isn't meant to be a tutorial and noone should try to
> learn C++ from the standard. Stroustrup's 4th edition of The C++
> Programming Language is much easier to read (but not all that much
> shorter) than the standard.

Granted, but no one ever confused the ARM with a tutorial.  It *was*
the standard, 23 years ago. It defined the language, with commentary,
in under 500 pages, and gave the compiler precious few UB
opportunities.  An experienced programmer could read it, learn the
language and rely on what he'd read.  

I understand the language has grown somewhat, but the equivalent book
would be 3000 pages today.  (The standard alone is 1300.)  A good deal
of it is devoted to Get Out of Jail Free cards for the compiler:
describing what might compile and not produce a deterministic result.
As with all the tut-tutting about type-punning, for example.  

When did this become a good idea?  

The compiler's job is to convert C ++ logic into machine logic, and to
reject anything it cannot do so with absolute assurance.  If I could
wish something for C++14, it would be a 90% reduction in UB
descriptions.  Let's define the behavior and be done with it.  By
removing ambiguity, maybe the definition the language would become
readable again.  

--jkl



More information about the Gcc-help mailing list