[fpc-devel] Breaking change in FPC 2.6.1

Sven Barth pascaldragon at googlemail.com
Tue May 1 22:15:27 CEST 2012


On 01.05.2012 20:17, Mattias Gaertner wrote:
> On Tue, 01 May 2012 15:05:57 +0200
> Sven Barth<pascaldragon at googlemail.com>  wrote:
>
>> [...]
>> You can locally disable warnings by using the $warn directive (not
>> documented yet it seems, but available in 2.6.0).
>>
>> It looks like this:
>>
>> {$warn MSGID (on|off|error)}
>>
>> * on: MSGID will be emitted as a warning
>> * off: MSGID will not be emitted
>> * error: MSGID will be emitted as an error (and handled as such by the
>> compiler!)
>>
>> You can find out the MSGID by passing "-vq" to the compiler then it will
>> additionally print the ID for each message it writes. For the case of
>> "deprecated" there are two message IDs: One which is used if a custom
>> message is given and one for the other case. For the first the ID is
>> 5066 and for the latter 5043.
>>
>> The following is a demonstration of the potential usage of $warn:
>>
>> === example begin ===
>>
>> program warntest;
>>
>> {$mode objfpc}
>>
>> type
>>     TTest = class
>>       procedure Test; deprecated 'Test';
>>     end;
>>
>> procedure TTest.Test;
>> begin
>>
>> end;
>>
>> var
>>     t: TTest;
>> begin
>> {$push} //<= used to restore the state afterwards; you could use {$warn
>> 5066 on} as well
>> {$warn 5066 off}
>>     t.Test; // here no warning will be emitted
>> {$pop}
>>     t.Test; // here a warning will be emitted
>> end.
>>
>> === example end ===
>>
>> Alternatively you can also use
>>
>> {$warn symbol_deprecated off}
>>
>> which will switch of both custom and non-custom deprecated messages for
>> symbols (units have an extra name).
>>
>> Here is a list of all those recognized identifiers (out of Delphi
>> compatibility):
>>
>> CONSTRUCTING_ABSTRACT
>> IMPLICIT_VARIANTS
>> NO_RETVAL
>> SYMBOL_DEPRECATED
>> SYMBOL_EXPERIMENTAL
>> SYMBOL_LIBRARY
>> SYMBOL_PLATFORM
>> SYMBOL_UNIMPLEMENTED
>> UNIT_DEPRECATED
>> UNIT_EXPERIMENTAL
>> UNIT_LIBRARY
>> UNIT_PLATFORM
>> UNIT_UNIMPLEMENTED
>> ZERO_NIL_COMPAT
>> IMPLICIT_STRING_CAST
>> IMPLICIT_VARIANTS
>> NO_RETVAL
>> SYMBOL_DEPRECATED
>> SYMBOL_EXPERIMENTAL
>> SYMBOL_LIBRARY
>> SYMBOL_PLATFORM
>> SYMBOL_UNIMPLEMENTED
>> UNIT_DEPRECATED
>> UNIT_EXPERIMENTAL
>> UNIT_LIBRARY
>> UNIT_PLATFORM
>> UNIT_UNIMPLEMENTED
>> ZERO_NIL_COMPAT
>> IMPLICIT_STRING_CAST
>> IMPLICIT_STRING_CAST_LOSS
>> EXPLICIT_STRING_CAST
>> EXPLICIT_STRING_CAST_LOSS
>> CVT_NARROWING_STRING_LOST
>
> Thanks. I added them to codetools.
> Is there a similar list for notes and hints?

These strings were added for Delphi compatibility and AFAIK there isn't 
any such feature for hints and notes. At least in FPC {$warn MSGID ...} 
DOES work for notes and hints messages, but I don't whether this is 
intentional or not... (just in case someone thinks that: setting a 
hint/note message to "on" using $warn does not make that message behave 
like a warning; it will still be a hint or note; {$warn ... error} does 
make the message behave like an error though)

As you added this to the codetools another note:
The following syntax is also supported:

{$warn MSGID +} for {$warn MSGID on}
{$warn MSGID -} for {$warn MSGID off}
(works for the mentioned identifiers as well)

Regards,
Sven



More information about the fpc-devel mailing list