Is the GCC optimazer too smart?

Andrew Haley aph@redhat.com
Thu Dec 10 12:11:00 GMT 2009


Revectored to gcc-help.

sergio borghese wrote:

> Now my question is: is it correct that the compiler enforces the
> constantness of the variable, even tought it states in the warning
> that the const qualifier has been discarded?

Yes.

Section 6.7.3, Type qualifiers

... If an attempt is made to modify an object defined with a
const-qualified type through use of an lvalue with non-const-qualified
type, the behavior is undefined. ...

The best way to answer questions like this is always to check the standard.

Andrew.



More information about the Gcc-help mailing list