[fpc-devel] Const optimization is a serious bug
Alexander Klenin
klenin at gmail.com
Tue Jul 5 18:27:39 CEST 2011
On Tue, Jul 5, 2011 at 22:51, Martin <fpc at mfriebe.de> wrote:
> 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.
Well, then the following changes are in order:
1) The documentation should recommend users to never use "const
string" parameters
except cases where they can prove it to be safe.
Moreover, since the safety of such code may be compromised by
completely unrelated changes
(e.g. by adding {$INLINE OFF} for debugging purposes),
"const" modifier should not be used at all except the most
performance-critical code.
This is quite the opposite of the current practice, where all string
parameters are usually
marked by "const".
2) All such incorrect usage should be removed from LCL and FCL
(for example: event handlers in LCL and TStrings methods in FCL).
Personally, I think this solution is inferior to my proposal of
implementing the optimization
correctly by default.
> 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)
Ok, FPC and Lazarus teams now have many bugs to fix ;-)
I''ll start reviewing my TAChart code in a few days.
--
Alexander S. Klenin
More information about the fpc-devel
mailing list