Switch -gv includes cmem unit
Original Reporter info from Mantis: Simon Ameis @SAmeis
-
Reporter name: Simon Ameis
Original Reporter info from Mantis: Simon Ameis @SAmeis
- Reporter name: Simon Ameis
Description:
The documentation of compiler switch -gv [1] doesnot state that the unit cmem will be automatically be included.
This leads to a "Duplicate identifier: CMEM" compiler error if cmem is included in project file.
[1] https://www.freepascal.org/docs-html/current/user/usersu15.html#x38-450005.1.4
Steps to reproduce:
By now you can use {$IF DECLARED(calloc)} to check if the function calloc of unit cmem is available outside of the uses clause. For this to work at least one other unit (also an empty unit) must be included in the uses clause.
<code>program Project1;
{$IF DECLARED(calloc)}
// compiled with -gv, this warning is issued
{$WARNING calloc defined}
{$ELSE}
// without -gv or without uses section at all
{$WARNING calloc NOT defined}
{$ENDIF}
var
p: Pointer;
begin
// this compiles well if -gv is used; although the message "calloc NOT defined" is issued above
p := CAlloc(1, 1);
Free(p);
end.</code>
This gives "Error: Duplicate identifier CMEM"
<code>program Project1;
{$IF NOT DECLARED(calloc)}
uses cmem;
{$ENDIF}
begin
end.</code>
This gives "Internal Error 200501152" independant of -gv switch.
<code>program Project1;
uses
{$IF NOT DECLARED(calloc)}
cmem
{$ENDIF}
SysUtils;
begin
end.</code>
Additional information:
Also there is no way to determine the usage of valgrind or unit cmem at compile time. The variable System.EntryInformation.valgrind_used is only set at runtime and there is no compile time condition available for this. To overcome this situation I see three options:
&LtPos;ol>
&LtPos;li>Define a new macro for each unit in the include list (implicit or explict)&LtPos;/li>
&LtPos;li>make {$IFOPT } compatible with command line switches&LtPos;/li>
&LtPos;li>make {$IF DECLARED() } compatible with unit names or full qualified identifiers or make it usable in uses clause&LtPos;/li>
&LtPos;/ol>