This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -funswitch-loops not effective?
Mark Mitchell <mark@codesourcery.com> wrote:
>>> Of course, this doesn't say where there is the well-formed
>>> leak of a pointer to the const member in the class in the first
>>> place:
>>>
>>> class Foo {
>>> public:
>>> Foo(bool b) : flag(b) {}
>>> bool get() const { return flag; }
>>> private:
>>> const bool flag;
>>> };
>>>
>>> Is there a well-formed way to write to Foo::flag?
>
> Yes -- but only during the constructor for Foo. After that point, it
> cannot change.
Actually, to clarify, only within the member initialization list of Foo's
constructor, where you can explicitally call the const member's constructor.
After that, the body of the construct of Foo is no different from other
member functions, in that it cannot modify the const member's contents.
--
Giovanni Bajo