This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: how to make gcc warn about arithmetic signed overflow
- From: "James K. Lowden" <jklowden at schemamania dot org>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 23 Sep 2013 00:03:55 -0400
- Subject: Re: how to make gcc warn about arithmetic signed overflow
- Authentication-results: sourceware.org; auth=none
- References: <20130921164609 dot GC3086 at a dot lan> <CAH6eHdTToM+TMy55m5HYo39DC8nA0RrTma1Bp5OnhUtPErMfOA at mail dot gmail dot com> <20130921174229 dot GD3086 at a dot lan> <CAH6eHdQzJNQY4Meysi259RheSaGscKUF28OW43OvOD1rf6FkxQ at mail dot gmail dot com>
On Sat, 21 Sep 2013 19:30:02 +0100
Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> > its value can be changed using pointers
>
> No, that's not true. You can't change the value of a const object in a
> valid program.
I don't know if we're talking C or C++ at this point, but const_cast
will surely let you change the value of a const object without treading
into undefined behavior.
Regarding the OP's query
> > int r = ab * bc;
although the provided example is simple enough, it's the compiler's
job is to generate object code, not to do static analysis.
Even if the values are const, in the general case they could be
modified by another module or another thread. The compiler simply
doesn't have enough information to warn of every runtime overflow.
--jkl