[fpc-devel] Const optimization is a serious bug
Martin
fpc at mfriebe.de
Tue Jul 5 13:51:16 CEST 2011
On 05/07/2011 11:24, michael.vancanneyt at wisa.be wrote:
>
>
> On Tue, 5 Jul 2011, Martin wrote:
>
>> On 05/07/2011 04:02, Chad Berchek wrote:
>>>
>>> Martin wrote:
>>>> I don't think it is a bug.
>>> ...
>>>> "(const s: string)" is a declaration by the programmer, that the
>>>> variable (the string) will not be modified at all. That is neither by
>>>> the procedure called, nor by any code outside the procedure, via any
>>>> other reference to the data. If the programmer sticks to what he
>>>> declared, then it works, if not it crashes.
>>>
>>> Is that true? I am not necessarily asserting that your statement is
>>> false; it could well be true. However I personally have not seen it
>>> documented so if anyone has a reference I would like to see it. As
>>> far as I have been able to tell from the docs of Delphi and FPC, the
>>> const declaration does NOT mean the programmer promises to not
>>> modify the instance; it means he promises to not modify the
>>> variable, which the compiler does indeed enforce.
>>
>> Well, I have pointed out myself,in my mail, that it probably needs
>> more documentation. I do not know if it is documented or not.
>>
>> But it is the answer, I have gotten several times from developers in
>> the FPC team. So for all I know it is the intended behaviour. At
>> least intended in FPC (and apparently either intended or at least
>> implemented in Delphi). So if there is no documentation for it, then
>> it would appear a problem of documentation, rather than a bug in the
>> compiler (Again all based on the statements I was given)
>
> There is no bug.
I think you misunderstood me. There is a (or there may be) a bug. But
*not* in the compiler, and *not* in the implementation of "const string".
I explicitly pointet that out on the top of the quotation "I don't think
it is a bug." (with reference to the feature itself)
The bug(s) is/are in user code, where the const construct is
*incorrectly* used.
An I was merely pointing out, that any usage without knowledge what it
does is incorrect usage (even if by accident it works). Therefore one
might consider such unaware/unknowing usage as a bug (a bug in the users
code)
More information about the fpc-devel
mailing list