[fpc-devel] "unused variable" depends on optimization?

Martin Frb lazarus at mfriebe.de
Sun Feb 23 14:14:48 CET 2025


Is it correct (i.e. by design) that the compiler emits some "may not be 
initialized" warnings, only on certain optimization levels?

The following is
- NOT given with -O1
- present with -O3

lazsyntextarea.pp(1325,54) Warning: Local variable "ViewedRange" does 
not seem to be initialized

O1 is actually right, it is always initialized, no warning needed. But I 
would accept that the compiler may not be able to deduce that.
However, if it does not, then should O1 also display the warning?



procedure TLazSynSurfaceManager.InvalidateLines(FirstTextLine,
   LastTextLine: TLineIdx; AScreenLineOffset: Integer);
var
   rcInval: TRect;
   ViewedRange: TLineRange;
begin
   rcInval := Bounds;
   if (FirstTextLine >= 0) then begin
     ViewedRange := DisplayView.TextToViewIndex(FirstTextLine);
     rcInval.Top := Max(TextArea.TextBounds.Top,
                        TextArea.TextBounds.Top + (ViewedRange.Top + 
AScreenLineOffset
                           - TextArea.TopLine + 1) * TextArea.LineHeight);
   end;
   if (LastTextLine >= 0) then begin
     if LastTextLine <> FirstTextLine then
       ViewedRange := DisplayView.TextToViewIndex(LastTextLine);
     rcInval.Bottom := Min(TextArea.TextBounds.Bottom, /////////////// 
<<<<<<< 1325
                           TextArea.TextBounds.Top + (ViewedRange.Bottom 
+ AScreenLineOffset
                              - TextArea.TopLine + 2)  * 
TextArea.LineHeight);
   end;



More information about the fpc-devel mailing list