Revision 2 of 3, by Kai Burghardt on 9-7-2022. The page as it is now.
$warn
{$warn} is a local compiler directive controlling emission of certain messages during compile-time. Messages do not necessarily have to be warnings, but can be messages of any kind. The directive may also promote specific messages to errors.
The (local) compiler directives {$warnings on} and {$warnings off} may turn on or off emission of all warnings all together.
usage
{$warn} requires a message label and a treatment option as arguments, like this:
{$warn 3250 off}The numeric message label can be retrieved during compilation with the -vq option supplied on the command-line (verbosity: show message numbers). Some messages and groups of messages have an alias, too, which can be seen in the table below.
Beside {$warn 3019 on} or {$warn 3019 off} and the shorthand notation {$warn 3019 +} and {$warn 3019 -} respectively, {$warn} may be used to promote messages to errors. {$warn symbol_experimental error} will make all, if any, hints concerning experimental symbols become (non-fatal) errors. Depending on the selected error treatment, the compiler may stop compiling or continue, unless a threshold of errors has been reached.
Note, demoting messages to errors is not possible. A {$fatal} error will always be fatal.
message labels
<table> <caption>FPC messages (excerpt)</caption> <thead> <tr> <th><p>index</p></th> <th><p>alias</p></th> <th><p>situations triggering the message</p></th> </tr> </thead> <tbody> <tr> <td><p><code>02024</code></p></td> <td></td> <td><ul> <li>there is a custom defined <code>{$warning}</code></li> </ul></td> </tr> <tr> <td><p><code>02077</code></p></td> <td></td> <td><ul> <li>the directive <code>{$minStackSize}</code> is used, but not supported on the current OS</li> </ul></td> </tr> <tr> <td><p><code>02078</code></p></td> <td></td> <td><ul> <li>the directive <code>{$maxStackSize}</code> is used, but not supported on the current OS</li> </ul></td> </tr> <tr> <td><p><code>03018</code></p></td> <td></td> <td><ul> <li>a <code>constructor</code> is not defined at <code>public</code> visibility level</li> </ul></td> </tr> <tr> <td><p><code>03019</code></p></td> <td></td> <td><ul> <li>a <code>destructor</code> is not defined at <code>public</code> visibility level</li> </ul></td> </tr> <tr> <td><p><code>03177</code></p></td> <td></td> <td><ul> <li>a <code>record</code> initialization does not define values for all fields</li> </ul></td> </tr> <tr> <td><p><code>03211</code></p></td> <td><p><code>implicit_variants</code></p></td> <td><ul> <li>the <code>variants</code> unit is required, but has not yet been loaded</li> </ul></td> </tr> <tr> <td><p><code>03250</code></p></td> <td></td> <td><ul> <li>a virtual method is overridden with lower visibility</li> </ul></td> </tr> <tr> <td><p><code>04044</code></p></td> <td></td> <td><ul> <li>a comparison might be always <code>false</code> (disjunct ranges)</li> </ul></td> </tr> <tr> <td><p><code>04045</code></p></td> <td></td> <td><ul> <li>a comparison might be always <code>true</code> (disjunct ranges)</li> </ul></td> </tr> <tr> <td><p><code>04046</code></p></td> <td><p><code>constructing_abstract</code></p></td> <td><ul> <li>constructing an instance of a class with abstract methods</li> </ul></td> </tr> <tr> <td><p><code>04056</code></p></td> <td></td> <td><ul> <li>a pointer to ordinal conversion is not portable</li> </ul></td> </tr> <tr> <td><p><code>04090</code></p></td> <td><p><code>zero_nil_compat</code></p></td> <td><ul> <li>converting <code>0</code> to nil (integer to pointer)</li> </ul></td> </tr> <tr> <td><p><code>04104</code></p></td> <td><p><code>implicit_string_cast</code></p></td> <td><ul> <li>implicit string type conversion</li> </ul></td> </tr> <tr> <td><p><code>04105</code></p></td> <td><p><code>implicit_string_cast_loss</code></p></td> <td><ul> <li>implicit string type conversion with potential data loss</li> </ul></td> </tr> <tr> <td><p><code>04106</code></p></td> <td><p><code>explicit_string_cast</code></p></td> <td><ul> <li>explicit string type conversion</li> </ul></td> </tr> <tr> <td><p><code>04107</code></p></td> <td><p><code>explicit_string_cast_loss</code></p></td> <td><ul> <li>explicit string type conversion with potential data loss</li> </ul></td> </tr> <tr> <td><p><code>04108</code></p></td> <td><p><code>cvt_narrowing_string_lost</code></p></td> <td><ul> <li>Unicode constant cast with potential data loss</li> </ul></td> </tr> <tr> <td><p><code>04116</code></p></td> <td><p><code>intf_raise_visibility</code></p></td> <td><ul> <li>the interface defines a broader visibility for a method</li> </ul></td> </tr> <tr> <td><p><code>04122</code></p></td> <td><p><code>constructing_abstract</code></p></td> <td><ul> <li>constructing an instance of an abstract class</li> </ul></td> </tr> <tr> <td><p><code>05023</code></p></td> <td></td> <td><ul> <li>a <code>unit</code> is imported, but not used (except units containing <code>initialization</code>/<code>finalization</code> code)</li> </ul></td> </tr> <tr> <td><p><code>05024</code></p></td> <td></td> <td><ul> <li>a routine parameter remains unused</li> </ul></td> </tr> <tr> <td><p><code>05033</code></p></td> <td><p><code>no_retval</code></p></td> <td><ul> <li>no (for the compiler obvious) assignment to a function’s return value</li> </ul></td> </tr> <tr> <td><p><code>05036</code></p></td> <td></td> <td><ul> <li>a variable which might not yet have been initialized is used</li> </ul></td> </tr> <tr> <td><p><code>05043</code></p></td> <td><p><code>symbol_deprecated</code></p></td> <td><ul> <li>a symbol with the <code>deprecated</code> hint (no deprecation message defined) is used</li> </ul></td> </tr> <tr> <td><p><code>05044</code></p></td> <td><p><code>symbol_platform</code></p></td> <td><ul> <li>a symbol with the <code>platform</code> hint is used</li> </ul></td> </tr> <tr> <td><p><code>05055</code></p></td> <td><p><code>symbol_unimplemented</code></p></td> <td><ul> <li>a symbol with the <code>unimplemented</code> hint is used</li> </ul></td> </tr> <tr> <td><p><code>05059</code></p></td> <td></td> <td><ul> <li>inside a function definition its result variable’s value is used, before it has been initialized</li> </ul></td> </tr> <tr> <td><p><code>05063</code></p></td> <td><p><code>symbol_experimental</code></p></td> <td><ul> <li>a symbol with the <code>experimental</code> hint is used</li> </ul></td> </tr> <tr> <td><p><code>05065</code></p></td> <td><p><code>symbol_library</code></p></td> <td><ul> <li>a library symbol is used</li> </ul></td> </tr> <tr> <td><p><code>05066</code></p></td> <td><p><code>symbol_deprecated</code></p></td> <td><ul> <li>a symbol with the <code>deprecated</code> hint is used and a custom deprecation notice has been defined</li> </ul></td> </tr> <tr> <td><p><code>05073</code></p></td> <td></td> <td><ul> <li>a <code>private property</code> remains unused</li> </ul></td> </tr> <tr> <td><p><code>05074</code></p></td> <td><p><code>unit_deprecated</code></p></td> <td><ul> <li>a unit with the <code>deprecated</code> hint (without a custom deprecation message supplied) is used</li> </ul></td> </tr> <tr> <td><p><code>05075</code></p></td> <td><p><code>unit_deprecated</code></p></td> <td><ul> <li>a unit with the <code>deprecated</code> hint is used and a custom deprecation notice has been defined</li> </ul></td> </tr> <tr> <td><p><code>05076</code></p></td> <td><p><code>unit_platform</code></p></td> <td><ul> <li>a unit with the <code>platform</code> hint is used</li> </ul></td> </tr> <tr> <td><p><code>05077</code></p></td> <td><p><code>unit_library</code></p></td> <td><ul> <li>[to be explained]</li> </ul></td> </tr> <tr> <td><p><code>05078</code></p></td> <td><p><code>unit_unimplemented</code></p></td> <td><ul> <li>a unit with the <code>unimplemented</code> hint is used</li> </ul></td> </tr> <tr> <td><p><code>05079</code></p></td> <td><p><code>unit_experimental</code></p></td> <td><ul> <li>a unit with the <code>experimental</code> hint is used</li> </ul></td> </tr> <tr> <td><p><code>06018</code></p></td> <td></td> <td><ul> <li>the compiler has determined there is, or might be, unreachable code</li> </ul></td> </tr> <tr> <td><p><code>07104</code></p></td> <td></td> <td><ul> <li>register indirect addressing with <code>ebp</code> is used in conjunction with a negative offset</li> </ul></td> </tr> </tbody> </table>
Note, some aliases identify multiple messages.
see also
- § “
$WARN: Control emission of warnings” in the Free Pascal programmer’s guide - {$message}
- Turn warnings and hints on or off
From the Free Pascal wiki, page "$warn", as it stood on 2022-09-07 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
