Sign in Join
Wiki copytemporary

$warn: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11`{$warn}` is a [[local compiler directives|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.
22
33The (local) compiler directives `{$warnings on}` and `{$warnings off}` may turn on or off emission of all *warnings* all together.
44
55## usage
66
77`{$warn}` requires a message label and a treatment option as arguments, like this:
88
99``` pascal
1010{$warn 3250 off}
1111```
1212
1313The 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.
1414
1515Beside `{$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, [[Hint Directives|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.
1616
1717Note, demoting messages to errors is not possible. A `{$fatal}` error will always be fatal.
1818
1919## message labels
2020
21-<table>
22-<caption>[[FPC]] messages (excerpt)</caption>
23-<thead>
24-<tr>
25-<th><p>index</p></th>
26-<th><p>alias</p></th>
27-<th><p>situations triggering the message</p></th>
28-</tr>
29-</thead>
30-<tbody>
31-<tr>
32-<td><p><code>02024</code></p></td>
33-<td></td>
34-<td><ul>
35-<li>there is a custom defined <code>{$warning}</code></li>
36-</ul></td>
37-</tr>
38-<tr>
39-<td><p><code>02077</code></p></td>
40-<td></td>
41-<td><ul>
42-<li>the directive <code>{$minStackSize}</code> is used, but not supported on the current OS</li>
43-</ul></td>
44-</tr>
45-<tr>
46-<td><p><code>02078</code></p></td>
47-<td></td>
48-<td><ul>
49-<li>the directive <code>{$maxStackSize}</code> is used, but not supported on the current OS</li>
50-</ul></td>
51-</tr>
52-<tr>
53-<td><p><code>03018</code></p></td>
54-<td></td>
55-<td><ul>
56-<li>a <code>constructor</code> is not defined at <code>public</code> visibility level</li>
57-</ul></td>
58-</tr>
59-<tr>
60-<td><p><code>03019</code></p></td>
61-<td></td>
62-<td><ul>
63-<li>a <code>destructor</code> is not defined at <code>public</code> visibility level</li>
64-</ul></td>
65-</tr>
66-<tr>
67-<td><p><code>03177</code></p></td>
68-<td></td>
69-<td><ul>
70-<li>a <code>record</code> initialization does not define values for all fields</li>
71-</ul></td>
72-</tr>
73-<tr>
74-<td><p><code>03211</code></p></td>
75-<td><p><code>implicit_variants</code></p></td>
76-<td><ul>
77-<li>the <code>variants</code> unit is required, but has not yet been loaded</li>
78-</ul></td>
79-</tr>
80-<tr>
81-<td><p><code>03250</code></p></td>
82-<td></td>
83-<td><ul>
84-<li>a virtual method is overridden with lower visibility</li>
85-</ul></td>
86-</tr>
87-<tr>
88-<td><p><code>04044</code></p></td>
89-<td></td>
90-<td><ul>
91-<li>a comparison might be always <code>false</code> (disjunct ranges)</li>
92-</ul></td>
93-</tr>
94-<tr>
95-<td><p><code>04045</code></p></td>
96-<td></td>
97-<td><ul>
98-<li>a comparison might be always <code>true</code> (disjunct ranges)</li>
99-</ul></td>
100-</tr>
101-<tr>
102-<td><p><code>04046</code></p></td>
103-<td><p><code>constructing_abstract</code></p></td>
104-<td><ul>
105-<li>constructing an instance of a class with abstract methods</li>
106-</ul></td>
107-</tr>
108-<tr>
109-<td><p><code>04056</code></p></td>
110-<td></td>
111-<td><ul>
112-<li>a pointer to ordinal conversion is not portable</li>
113-</ul></td>
114-</tr>
115-<tr>
116-<td><p><code>04090</code></p></td>
117-<td><p><code>zero_nil_compat</code></p></td>
118-<td><ul>
119-<li>converting <code>0</code> to [[Nil|nil]] (integer to pointer)</li>
120-</ul></td>
121-</tr>
122-<tr>
123-<td><p><code>04104</code></p></td>
124-<td><p><code>implicit_string_cast</code></p></td>
125-<td><ul>
126-<li>implicit string type conversion</li>
127-</ul></td>
128-</tr>
129-<tr>
130-<td><p><code>04105</code></p></td>
131-<td><p><code>implicit_string_cast_loss</code></p></td>
132-<td><ul>
133-<li>implicit string type conversion with potential data loss</li>
134-</ul></td>
135-</tr>
136-<tr>
137-<td><p><code>04106</code></p></td>
138-<td><p><code>explicit_string_cast</code></p></td>
139-<td><ul>
140-<li>explicit string type conversion</li>
141-</ul></td>
142-</tr>
143-<tr>
144-<td><p><code>04107</code></p></td>
145-<td><p><code>explicit_string_cast_loss</code></p></td>
146-<td><ul>
147-<li>explicit string type conversion with potential data loss</li>
148-</ul></td>
149-</tr>
150-<tr>
151-<td><p><code>04108</code></p></td>
152-<td><p><code>cvt_narrowing_string_lost</code></p></td>
153-<td><ul>
154-<li>Unicode constant cast with potential data loss</li>
155-</ul></td>
156-</tr>
157-<tr>
158-<td><p><code>04116</code></p></td>
159-<td><p><code>intf_raise_visibility</code></p></td>
160-<td><ul>
161-<li>the interface defines a broader visibility for a method</li>
162-</ul></td>
163-</tr>
164-<tr>
165-<td><p><code>04122</code></p></td>
166-<td><p><code>constructing_abstract</code></p></td>
167-<td><ul>
168-<li>constructing an instance of an abstract class</li>
169-</ul></td>
170-</tr>
171-<tr>
172-<td><p><code>05023</code></p></td>
173-<td></td>
174-<td><ul>
175-<li>a <code>unit</code> is imported, but not used (except units containing <code>initialization</code>/<code>finalization</code> code)</li>
176-</ul></td>
177-</tr>
178-<tr>
179-<td><p><code>05024</code></p></td>
180-<td></td>
181-<td><ul>
182-<li>a routine parameter remains unused</li>
183-</ul></td>
184-</tr>
185-<tr>
186-<td><p><code>05033</code></p></td>
187-<td><p><code>no_retval</code></p></td>
188-<td><ul>
189-<li>no (for the compiler obvious) assignment to a function’s return value</li>
190-</ul></td>
191-</tr>
192-<tr>
193-<td><p><code>05036</code></p></td>
194-<td></td>
195-<td><ul>
196-<li>a variable which might not yet have been initialized is used</li>
197-</ul></td>
198-</tr>
199-<tr>
200-<td><p><code>05043</code></p></td>
201-<td><p><code>symbol_deprecated</code></p></td>
202-<td><ul>
203-<li>a symbol with the <code>deprecated</code> hint (no deprecation message defined) is used</li>
204-</ul></td>
205-</tr>
206-<tr>
207-<td><p><code>05044</code></p></td>
208-<td><p><code>symbol_platform</code></p></td>
209-<td><ul>
210-<li>a symbol with the <code>platform</code> hint is used</li>
211-</ul></td>
212-</tr>
213-<tr>
214-<td><p><code>05055</code></p></td>
215-<td><p><code>symbol_unimplemented</code></p></td>
216-<td><ul>
217-<li>a symbol with the <code>unimplemented</code> hint is used</li>
218-</ul></td>
219-</tr>
220-<tr>
221-<td><p><code>05059</code></p></td>
222-<td></td>
223-<td><ul>
224-<li>inside a function definition its result variable’s value is used, before it has been initialized</li>
225-</ul></td>
226-</tr>
227-<tr>
228-<td><p><code>05063</code></p></td>
229-<td><p><code>symbol_experimental</code></p></td>
230-<td><ul>
231-<li>a symbol with the <code>experimental</code> hint is used</li>
232-</ul></td>
233-</tr>
234-<tr>
235-<td><p><code>05065</code></p></td>
236-<td><p><code>symbol_library</code></p></td>
237-<td><ul>
238-<li>a library symbol is used</li>
239-</ul></td>
240-</tr>
241-<tr>
242-<td><p><code>05066</code></p></td>
243-<td><p><code>symbol_deprecated</code></p></td>
244-<td><ul>
245-<li>a symbol with the <code>deprecated</code> hint is used and a custom deprecation notice has been defined</li>
246-</ul></td>
247-</tr>
248-<tr>
249-<td><p><code>05073</code></p></td>
250-<td></td>
251-<td><ul>
252-<li>a <code>private property</code> remains unused</li>
253-</ul></td>
254-</tr>
255-<tr>
256-<td><p><code>05074</code></p></td>
257-<td><p><code>unit_deprecated</code></p></td>
258-<td><ul>
259-<li>a unit with the <code>deprecated</code> hint (without a custom deprecation message supplied) is used</li>
260-</ul></td>
261-</tr>
262-<tr>
263-<td><p><code>05075</code></p></td>
264-<td><p><code>unit_deprecated</code></p></td>
265-<td><ul>
266-<li>a unit with the <code>deprecated</code> hint is used and a custom deprecation notice has been defined</li>
267-</ul></td>
268-</tr>
269-<tr>
270-<td><p><code>05076</code></p></td>
271-<td><p><code>unit_platform</code></p></td>
272-<td><ul>
273-<li>a unit with the <code>platform</code> hint is used</li>
274-</ul></td>
275-</tr>
276-<tr>
277-<td><p><code>05077</code></p></td>
278-<td><p><code>unit_library</code></p></td>
279-<td><ul>
280-<li>[to be explained]</li>
281-</ul></td>
282-</tr>
283-<tr>
284-<td><p><code>05078</code></p></td>
285-<td><p><code>unit_unimplemented</code></p></td>
286-<td><ul>
287-<li>a unit with the <code>unimplemented</code> hint is used</li>
288-</ul></td>
289-</tr>
290-<tr>
291-<td><p><code>05079</code></p></td>
292-<td><p><code>unit_experimental</code></p></td>
293-<td><ul>
294-<li>a unit with the <code>experimental</code> hint is used</li>
295-</ul></td>
296-</tr>
297-<tr>
298-<td><p><code>06018</code></p></td>
299-<td></td>
300-<td><ul>
301-<li>the compiler has determined there is, or might be, unreachable code</li>
302-</ul></td>
303-</tr>
304-<tr>
305-<td><p><code>07104</code></p></td>
306-<td></td>
307-<td><ul>
308-<li>register indirect addressing with <code>ebp</code> is used in conjunction with a negative offset</li>
309-</ul></td>
310-</tr>
311-</tbody>
312-</table>
21+[[FPC]] messages (excerpt)
22+
23+**index**
24+
25+**alias**
26+
27+**situations triggering the message**
28+
29+`02024`
30+
31+- there is a custom defined `{$warning}`
32+
33+`02077`
34+
35+- the directive `{$minStackSize}` is used, but not supported on the current OS
36+
37+`02078`
38+
39+- the directive `{$maxStackSize}` is used, but not supported on the current OS
40+
41+`03018`
42+
43+- a `constructor` is not defined at `public` visibility level
44+
45+`03019`
46+
47+- a `destructor` is not defined at `public` visibility level
48+
49+`03177`
50+
51+- a `record` initialization does not define values for all fields
52+
53+`03211`
54+
55+`implicit_variants`
56+
57+- the `variants` unit is required, but has not yet been loaded
58+
59+`03250`
60+
61+- a virtual method is overridden with lower visibility
62+
63+`04044`
64+
65+- a comparison might be always `false` (disjunct ranges)
66+
67+`04045`
68+
69+- a comparison might be always `true` (disjunct ranges)
70+
71+`04046`
72+
73+`constructing_abstract`
74+
75+- constructing an instance of a class with abstract methods
76+
77+`04056`
78+
79+- a pointer to ordinal conversion is not portable
80+
81+`04090`
82+
83+`zero_nil_compat`
84+
85+- converting `0` to [[Nil|nil]] (integer to pointer)
86+
87+`04104`
88+
89+`implicit_string_cast`
90+
91+- implicit string type conversion
92+
93+`04105`
94+
95+`implicit_string_cast_loss`
96+
97+- implicit string type conversion with potential data loss
98+
99+`04106`
100+
101+`explicit_string_cast`
102+
103+- explicit string type conversion
104+
105+`04107`
106+
107+`explicit_string_cast_loss`
108+
109+- explicit string type conversion with potential data loss
110+
111+`04108`
112+
113+`cvt_narrowing_string_lost`
114+
115+- Unicode constant cast with potential data loss
116+
117+`04116`
118+
119+`intf_raise_visibility`
120+
121+- the interface defines a broader visibility for a method
122+
123+`04122`
124+
125+`constructing_abstract`
126+
127+- constructing an instance of an abstract class
128+
129+`05023`
130+
131+- a `unit` is imported, but not used (except units containing `initialization`/`finalization` code)
132+
133+`05024`
134+
135+- a routine parameter remains unused
136+
137+`05033`
138+
139+`no_retval`
140+
141+- no (for the compiler obvious) assignment to a function’s return value
142+
143+`05036`
144+
145+- a variable which might not yet have been initialized is used
146+
147+`05043`
148+
149+`symbol_deprecated`
150+
151+- a symbol with the `deprecated` hint (no deprecation message defined) is used
152+
153+`05044`
154+
155+`symbol_platform`
156+
157+- a symbol with the `platform` hint is used
158+
159+`05055`
160+
161+`symbol_unimplemented`
162+
163+- a symbol with the `unimplemented` hint is used
164+
165+`05059`
166+
167+- inside a function definition its result variable’s value is used, before it has been initialized
168+
169+`05063`
170+
171+`symbol_experimental`
172+
173+- a symbol with the `experimental` hint is used
174+
175+`05065`
176+
177+`symbol_library`
178+
179+- a library symbol is used
180+
181+`05066`
182+
183+`symbol_deprecated`
184+
185+- a symbol with the `deprecated` hint is used and a custom deprecation notice has been defined
186+
187+`05073`
188+
189+- a `private property` remains unused
190+
191+`05074`
192+
193+`unit_deprecated`
194+
195+- a unit with the `deprecated` hint (without a custom deprecation message supplied) is used
196+
197+`05075`
198+
199+`unit_deprecated`
200+
201+- a unit with the `deprecated` hint is used and a custom deprecation notice has been defined
202+
203+`05076`
204+
205+`unit_platform`
206+
207+- a unit with the `platform` hint is used
208+
209+`05077`
210+
211+`unit_library`
212+
213+- \[to be explained\]
214+
215+`05078`
216+
217+`unit_unimplemented`
218+
219+- a unit with the `unimplemented` hint is used
220+
221+`05079`
222+
223+`unit_experimental`
224+
225+- a unit with the `experimental` hint is used
226+
227+`06018`
228+
229+- the compiler has determined there is, or might be, unreachable code
230+
231+`07104`
232+
233+- register indirect addressing with `ebp` is used in conjunction with a negative offset
313234
314235Note, some aliases identify *multiple* messages.
315236
316237## see also
317238
318239- [§ “`$WARN`: Control emission of warnings” in the *Free Pascal programmer’s guide*](https://www.freepascal.org/docs-html/prog/progsu80.html)
319240- [[$message|{$message}]]
320241- [[Turn warnings and hints on or off]]
321242
322243---
323244*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](/wiki-contact).*
324245Category: FPC
325246Category: Local compiler directives

Back to history