[fpc-pascal] weird compiler(?) problem

Xiangrong Fang xrfang at gmail.com
Thu Feb 13 16:42:19 CET 2014


Hi All,

I encountered a very strange problem.  The code looks like this:

//In Unit1.pas:

//sel is an object of TIntVector and
//TIntVector = specialize TVector<Integer>

*sel.Sort([soEliminateNA, soReversed]); *

//In vector.pas:

procedure TVector.Sort(Options: SortOptions);
var
  i, gap, order, first, last, pos: Integer;
  Temp: T;
begin
  *if FCount < 2 then** Exit;  <-- problem here*
  if soReversed in Options then order := 1 else order := -1;
  ... ...

My purpose is to skip sorting if the vector's element count is less than 2.

Now the problem is that this statement does not have any effect (see
attached screenshot).  The debugger refuse to stop on the breakpoint, but
goes directly to the line below it!

What's more strange is that if I change the line to break after “then”,
i.e.:

begin
  *if FCount < 2 then*
*    Exit;*
  if soReversed in Options then order := 1 else order := -1;
  ... ...

Now it worked!

I also wrote a simple test program, but can NOT reproduce this bug there.

My TVector source code is here:
https://github.com/xrfang/fpcollection/blob/master/src/units/vector.pas


Any help is greatly appreciated.

Sincerely,
Xiangrong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140213/2777a8ca/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screen.png
Type: image/png
Size: 30913 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140213/2777a8ca/attachment.png>


More information about the fpc-pascal mailing list