import source from 1.3.40
[external/swig.git] / Doc / Manual / Warnings.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <title>Warning Messages</title>
5 <link rel="stylesheet" type="text/css" href="style.css">
6 </head>
7
8 <body bgcolor="#ffffff">
9 <H1><a name="Warnings"></a>14 Warning Messages</H1>
10 <!-- INDEX -->
11 <div class="sectiontoc">
12 <ul>
13 <li><a href="#Warnings_nn2">Introduction</a>
14 <li><a href="#Warnings_suppression">Warning message suppression</a>
15 <li><a href="#Warnings_nn4">Enabling extra warnings</a>
16 <li><a href="#Warnings_nn5">Issuing a warning message</a>
17 <li><a href="#Warnings_symbolic_symbols">Symbolic symbols</a>
18 <li><a href="#Warnings_nn6">Commentary</a>
19 <li><a href="#Warnings_nn7">Warnings as errors</a>
20 <li><a href="#Warnings_nn8">Message output format</a>
21 <li><a href="#Warnings_nn9">Warning number reference</a>
22 <ul>
23 <li><a href="#Warnings_nn10">Deprecated features (100-199)</a>
24 <li><a href="#Warnings_nn11">Preprocessor (200-299)</a>
25 <li><a href="#Warnings_nn12">C/C++ Parser (300-399)</a>
26 <li><a href="#Warnings_nn13">Types and typemaps (400-499) </a>
27 <li><a href="#Warnings_nn14">Code generation (500-599)</a>
28 <li><a href="#Warnings_nn15">Language module specific (800-899) </a>
29 <li><a href="#Warnings_nn16">User defined (900-999)</a>
30 </ul>
31 <li><a href="#Warnings_nn17">History</a>
32 </ul>
33 </div>
34 <!-- INDEX -->
35
36
37
38 <H2><a name="Warnings_nn2"></a>14.1 Introduction</H2>
39
40
41 <p>
42 During compilation, SWIG may generate a variety of warning messages.  For example:
43 </p>
44
45 <div class="shell">
46 <pre>
47 example.i:16: Warning(501): Overloaded declaration ignored.  bar(double)
48 example.i:15: Warning(501): Previous declaration is bar(int)
49 </pre>
50 </div>
51
52 <p>
53 Typically, warning messages indicate non-fatal problems with the input
54 where the generated wrapper code will probably compile, but it may not
55 work like you expect.
56 </p>
57
58 <H2><a name="Warnings_suppression"></a>14.2 Warning message suppression</H2>
59
60
61 <p>
62 All warning messages have a numeric code that is shown in the warning message itself.
63 To suppress the printing of a warning message, a number of techniques can be used.
64 First, you can run SWIG with the <tt>-w</tt> command line option. For example:
65 </p>
66
67 <div class="shell">
68 <pre>
69 % swig -python -w501 example.i
70 % swig -python -w501,505,401 example.i
71 </pre>
72 </div>
73
74 <p>
75 Alternatively, warnings can be suppressed by inserting a special preprocessor pragma
76 into the input file:
77 </p>
78
79 <div class="code">
80 <pre>
81 %module example
82 #pragma SWIG nowarn=501
83 #pragma SWIG nowarn=501,505,401
84 </pre>
85 </div>
86
87 <p>
88 Finally, code-generation warnings can be disabled on a declaration by declaration basis using
89 the <tt>%warnfilter</tt> directive.  For example:
90 </p>
91
92 <div class="code">
93 <pre>
94 %module example
95 %warnfilter(501) foo;
96 ...
97 int foo(int);
98 int foo(double);              // Silently ignored.
99 </pre>
100 </div>
101
102 <p>
103 The <tt>%warnfilter</tt> directive has the same semantics as other declaration modifiers like 
104 <tt>%rename</tt>, <tt>%ignore</tt> and <tt>%feature</tt>, see the 
105 <a href="Customization.html#features">%feature directive</a> section.  For example, if you wanted to
106 suppress a warning for a method in a class hierarchy, you could do this:
107 </p>
108
109 <div class="code">
110 <pre>
111 %warnfilter(501) Object::foo;
112 class Object {
113 public:
114    int foo(int);
115    int foo(double);      // Silently ignored
116    ...
117 };
118
119 class Derived : public Object {
120 public:
121    int foo(int);
122    int foo(double);      // Silently ignored
123    ...
124 };
125 </pre>
126 </div>
127
128 <p>
129 Warnings can be suppressed for an entire class by supplying a class name.  For example:
130 </p>
131
132 <div class="code">
133 <pre>
134 %warnfilter(501) Object;
135
136 class Object {
137 public:
138    ...                      // All 501 warnings ignored in class
139 };
140 </pre>
141 </div>
142
143 <p>
144 There is no option to suppress all SWIG warning messages.  The warning messages are there
145 for a reason---to tell you that something may be <em>broken</em> in
146 your interface.  Ignore the warning messages at your own peril.
147 </p>
148
149
150 <H2><a name="Warnings_nn4"></a>14.3 Enabling extra warnings</H2>
151
152
153 <p>
154 Some warning messages are disabled by default and are generated only
155 to provide additional diagnostics.  These warnings can be turned on using the
156 <tt>-Wextra</tt> option. For example:
157 </p>
158
159 <div class="shell">
160 <pre>
161 % swig -Wextra -python example.i
162 </pre>
163 </div>
164
165 <p>
166 To selectively turn on extra warning messages, you can use the directives and options in the
167 previous section--simply add a "+" to all warning numbers.  For example:
168 </p>
169
170 <div class="shell">
171 <pre>
172 % swig -w+309,+452 example.i
173 </pre>
174 </div>
175
176 <p>
177 or in your interface file use either
178 </p>
179
180 <div class="code">
181 <pre>
182 #pragma SWIG nowarn=+309,+452
183 </pre>
184 </div>
185
186 <p>
187 or
188 </p>
189
190 <div class="code">
191 <pre>
192 %warnfilter(+309,+452) foo;
193 </pre>
194 </div>
195
196 <p>
197 Note: selective enabling of warnings with <tt>%warnfilter</tt> overrides any global settings you might have
198 made using <tt>-w</tt> or <tt>#pragma</tt>.
199 </p>
200
201 <p>
202 You can of course also enable all warnings and suppress a select few, for example:
203 </p>
204
205 <div class="shell">
206 <pre>
207 % swig -Wextra -w309,452 example.i
208 </pre>
209 </div>
210
211 <p>
212 The warnings on the right take precedence over the warnings on the left, so in the above example <tt>-Wextra</tt> adds numerous warnings including 452, but then <tt>-w309,452</tt> overrides this and so 452 is suppressesed.
213 </p>
214
215 <p>
216 If you would like all warnings to appear, regardless of the warning filters used, then use the <tt>-Wall</tt> option.
217 The <tt>-Wall</tt> option also turns on the extra warnings that <tt>-Wextra</tt> adds, however, it is subtely different. 
218 When <tt>-Wall</tt> is used, it also disables all other warning filters, 
219 that is, any warnings suppressed or added in <tt>%warnfilter</tt>, <tt>#pragma SWIG nowarn</tt> 
220 or the <tt>-w</tt> option.
221 </p>
222
223 <H2><a name="Warnings_nn5"></a>14.4 Issuing a warning message</H2>
224
225
226 <p>
227 Warning messages can be issued from an interface file using a number of directives.  The
228 <tt>%warn</tt> directive is the most simple:
229 </p>
230
231 <div class="code">
232 <pre>
233 %warn "900:This is your last warning!"
234 </pre>
235 </div>
236
237 <p>
238 All warning messages are optionally prefixed by the warning number to use.  If you are generating
239 your own warnings, make sure you don't use numbers defined in the table at the end of this section.
240 </p>
241
242 <p>
243 The <tt>%ignorewarn</tt> directive is the same as <tt>%ignore</tt> except that it issues a
244 warning message whenever a matching declaration is found. For example:
245 </p>
246
247 <div class="code">
248 <pre>
249 %ignorewarn("362:operator= ignored") operator=;
250 </pre>
251 </div>
252
253 <p>
254 Warning messages can be associated with typemaps using the
255 <tt>warning</tt> attribute of a typemap declaration. For example:
256 </p>
257
258 <div class="code">
259 <pre>
260 %typemap(in, warning="901:You are really going to regret this") blah * {
261    ...
262 }
263 </pre>
264 </div>
265
266 <p>
267 In this case, the warning message will be printed whenever the typemap is actually used.
268 </p>
269
270 <H2><a name="Warnings_symbolic_symbols"></a>14.5 Symbolic symbols</H2>
271
272
273 <p>
274 The <tt>swigwarn.swg</tt> file that is installed with SWIG contains symbol constants that could also be
275 used in <tt>%warnfilter</tt> and <tt>#pragma SWIG nowarn</tt>.
276 For example this file contains the following line:
277 </p>
278
279 <div class="code">
280 <pre>
281 %define SWIGWARN_TYPE_UNDEFINED_CLASS 401 %enddef
282 </pre>
283 </div>
284
285 <p>
286 so <tt>SWIGWARN_TYPE_UNDEFINED_CLASS</tt> could be used instead of 401, for example:
287 </p>
288
289 <div class="code">
290 <pre>
291 #pragma SWIG nowarn=SWIGWARN_TYPE_UNDEFINED_CLASS
292 </pre>
293 </div>
294
295 <p>
296 or 
297 </p>
298
299 <div class="code">
300 <pre>
301 %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Foo;
302 </pre>
303 </div>
304
305 <H2><a name="Warnings_nn6"></a>14.6 Commentary</H2>
306
307
308 <p>
309 The ability to suppress warning messages is really only provided for
310 advanced users and is not recommended in normal use.  You are advised
311 to modify your interface to fix the problems highlighted by the warnings
312 wherever possible instead of suppressing warnings.
313 </p>
314
315 <p>
316 Certain types of SWIG problems are errors.  These usually arise due to
317 parsing errors (bad syntax) or semantic problems for which there is
318 no obvious recovery.  There is no mechanism for suppressing error
319 messages.
320 </p>
321
322 <H2><a name="Warnings_nn7"></a>14.7 Warnings as errors</H2>
323
324
325 <p>
326 Warnings can be handled as errors by using the <tt>-Werror</tt> command line
327 option. This will cause SWIG to exit with a non successful exit code if a
328 warning is encountered.
329 </p>
330
331 <H2><a name="Warnings_nn8"></a>14.8 Message output format</H2>
332
333
334 <p>
335 The output format for both warnings and errors can be selected for
336 integration with your favourite IDE/editor. Editors and IDEs can usually parse 
337 error messages and if in the appropriate format will easily take you 
338 directly to the source of the error. The standard format is used by 
339 default except on Windows where the Microsoft format is used by default.
340 These can be overridden using command line options, for example:
341 </p>
342
343 <div class="shell"><pre>
344 $ swig -python -Fstandard example.i
345 example.i:4: Syntax error in input.
346 $ swig -python -Fmicrosoft example.i
347 example.i(4): Syntax error in input.
348 </pre></div>
349
350 <H2><a name="Warnings_nn9"></a>14.9 Warning number reference</H2>
351
352
353 <H3><a name="Warnings_nn10"></a>14.9.1 Deprecated features (100-199)</H3>
354
355
356 <ul>
357 <li>101. Deprecated <tt>%extern</tt> directive.
358 <li>102. Deprecated <tt>%val</tt> directive.
359 <li>103. Deprecated <tt>%out</tt> directive.
360 <li>104. Deprecated <tt>%disabledoc</tt> directive.
361 <li>105. Deprecated <tt>%enabledoc</tt> directive.
362 <li>106. Deprecated <tt>%doconly</tt> directive.
363 <li>107. Deprecated <tt>%style</tt> directive.
364 <li>108. Deprecated <tt>%localstyle</tt> directive.
365 <li>109. Deprecated <tt>%title</tt> directive.
366 <li>110. Deprecated <tt>%section</tt> directive.
367 <li>111. Deprecated <tt>%subsection</tt> directive.
368 <li>112. Deprecated <tt>%subsubsection</tt> directive.
369 <li>113. Deprecated <tt>%addmethods</tt> directive.
370 <li>114. Deprecated <tt>%readonly</tt> directive.
371 <li>115. Deprecated <tt>%readwrite</tt> directive.
372 <li>116. Deprecated <tt>%except</tt> directive.
373 <li>117. Deprecated <tt>%new</tt> directive.
374 <li>118. Deprecated <tt>%typemap(except)</tt>.
375 <li>119. Deprecated <tt>%typemap(ignore)</tt>.
376 <li>120. Deprecated command line option (-runtime, -noruntime).
377 <li>121. Deprecated <tt>%name</tt> directive.
378 </ul>
379
380 <H3><a name="Warnings_nn11"></a>14.9.2 Preprocessor (200-299)</H3>
381
382
383 <ul>
384 <li>201. Unable to find 'filename'.
385 <li>202. Could not evaluate 'expr'.
386 </ul>
387
388 <H3><a name="Warnings_nn12"></a>14.9.3 C/C++ Parser (300-399)</H3>
389
390
391 <ul>
392 <li>301. <tt>class</tt> keyword used, but not in C++ mode.
393 <li>302. Identifier '<em>name</em>' redefined (ignored).
394 <li>303. <tt>%extend</tt> defined for an undeclared class '<em>name</em>'.
395 <li>304. Unsupported constant value (ignored).
396 <li>305. Bad constant value (ignored).
397 <li>306. '<em>identifier</em>' is private in this context.
398 <li>307. Can't set default argument value (ignored)
399 <li>308. Namespace alias '<em>name</em>' not allowed here. Assuming '<em>name</em>'
400 <li>309. [private | protected] inheritance ignored.
401 <li>310. Template '<em>name</em>' was already wrapped as '<em>name</em>' (ignored)
402 <li>311. Template partial specialization not supported.
403 <li>312. Nested classes not currently supported (ignored).
404 <li>313. Unrecognized extern type "<em>name</em>" (ignored).
405 <li>314. '<em>identifier</em>' is a <em>lang</em> keyword.
406 <li>315. Nothing known about '<em>identifier</em>'.
407 <li>316. Repeated %module directive.
408 <li>317. Specialization of non-template '<em>name</em>'.
409 <li>318. Instantiation of template <em>name</em> is ambiguous. Using <em>templ</em> at <em>file</em>:<em>line</em>
410 <li>319. No access specifier given for base class <em>name</em> (ignored).
411 <li>320. Explicit template instantiation ignored.
412 <li>321. <em>identifier</em> conflicts with a built-in name.
413 <li>322. Redundant redeclaration of '<em>name</em>'.
414 <li>350. operator new ignored.
415 <li>351. operator delete ignored.
416 <li>352. operator+ ignored.
417 <li>353. operator- ignored.
418 <li>354. operator* ignored.
419 <li>355. operator/ ignored.
420 <li>356. operator% ignored.
421 <li>357. operator^ ignored.
422 <li>358. operator&amp; ignored.
423 <li>359. operator| ignored.
424 <li>360. operator~ ignored.
425 <li>361. operator! ignored.
426 <li>362. operator= ignored.
427 <li>363. operator&lt; ignored.
428 <li>364. operator&gt; ignored.
429 <li>365. operator+= ignored.
430 <li>366. operator-= ignored.
431 <li>367. operator*= ignored.
432 <li>368. operator/= ignored.
433 <li>369. operator%= ignored.
434 <li>370. operator^= ignored.
435 <li>371. operator&amp;= ignored.
436 <li>372. operator|= ignored.
437 <li>373. operator&lt;&lt; ignored.
438 <li>374. operator&gt;&gt;ignored.
439 <li>375. operator&lt;&lt;= ignored.
440 <li>376. operator&gt;&gt;= ignored.
441 <li>377. operator== ignored.
442 <li>378. operator!= ignored.
443 <li>379. operator&lt;= ignored.
444 <li>380. operator&gt;= ignored.
445 <li>381. operator&amp;&amp; ignored.
446 <li>382. operator|| ignored.
447 <li>383. operator++ ignored.
448 <li>384. operator-- ignored.
449 <li>385. operator, ignored.
450 <li>386. operator-&lt;* ignored.
451 <li>387. operator-&lt; ignored.
452 <li>388. operator() ignored.
453 <li>389. operator[] ignored.
454 <li>390. operator+ ignored (unary).
455 <li>391. operator- ignored (unary).
456 <li>392. operator* ignored (unary).
457 <li>393. operator&amp; ignored (unary).
458 <li>394. operator new[] ignored.
459 <li>395. operator delete[] ignored.
460 </ul>
461
462 <H3><a name="Warnings_nn13"></a>14.9.4 Types and typemaps (400-499) </H3>
463
464
465 <ul>
466 <li>401. Nothing known about class 'name'. Ignored.
467 <li>402. Base class 'name' is incomplete.
468 <li>403. Class 'name' might be abstract.
469 <li>450. Deprecated typemap feature ($source/$target).
470 <li>451. Setting const char * variable may leak memory.
471 <li>452. Reserved
472 <li>453. Can't apply (pattern). No typemaps are defined.
473 <li>460. Unable to use type <em>type</em> as a function argument.
474 <li>461. Unable to use return type <em>type</em> in function <em>name</em>.
475 <li>462. Unable to set variable of type <em>type</em>.
476 <li>463. Unable to read variable of type <em>type</em>.
477 <li>464. Unsupported constant value.
478 <li>465. Unable to handle type <em>type</em>.
479 <li>466. Unsupported variable type <em>type</em>.
480 <li>467. Overloaded <em>declaration</em> not supported (no type checking rule for '<em>type</em>')
481 <li>468. No 'throw' typemap defined for exception type <em>type</em>
482 <li>469. No or improper directorin typemap defined for <em>type</em>
483 <li>470. Thread/reentrant unsafe wrapping, consider returning by value instead.
484 <li>471. Unable to use return type <em>type</em> in director method
485 <li>474. Method <em>method</em> usage of the optimal attribute in the out typemap at <em>file</em>:<em>line</em> ignored as the following cannot be used to generate optimal code: <em>code</em>
486 <li>475. Multiple calls to <em>method</em> might be generated due to optimal attribute usage in the out typemap at <em>file</em>:<em>line</em>.
487 </ul>
488
489
490
491 <H3><a name="Warnings_nn14"></a>14.9.5 Code generation (500-599)</H3>
492
493
494 <ul>
495 <li>501. Overloaded declaration ignored. <em>decl</em>
496 <li>502. Overloaded constructor ignored. <em>decl</em>
497 <li>503. Can't wrap '<em>identifier</em>' unless renamed to a valid identifier.
498 <li>504. Function <em>name</em> must have a return type.
499 <li>505. Variable length arguments discarded.
500 <li>506. Can't wrap varargs with keyword arguments enabled.
501 <li>507. Adding native function <em>name</em> not supported (ignored).
502 <li>508. Declaration of '<em>name</em>' shadows declaration accessible via operator-&gt;() at <em>file:line</em>.
503 <li>509. Overloaded <em>declaration</em> is shadowed by <em>declaration</em> at <em>file</em>:<em>line</em>.
504 <li>510. Friend function '<em>name</em>' ignored.
505 <li>511. Can't use keyword arguments with overloaded functions.
506 <li>512. Overloaded <em>declaration</em> const ignored. Non-const method at <em>file</em>:<em>line</em> used.
507 <li>513. Can't generate wrappers for unnamed struct/class.
508 <li>514. 
509 <li>515. 
510 <li>516. Overloaded method <em>declaration</em> ignored. Method <em>declaration</em> at <em>file</em>:<em>line</em> used.
511 <li>517. 
512 <li>518. Portability warning: File <em>file1</em> will be overwritten by <em>file2</em> on case insensitive filesystems such as Windows' FAT32 and NTFS unless the class/module name is renamed.
513 <li>519. %template() contains no name. Template method ignored: <em>declaration</em>
514 </ul>
515
516 <H3><a name="Warnings_nn15"></a>14.9.6 Language module specific (800-899) </H3>
517
518
519 <ul>
520 <li>801. Wrong name (corrected to '<em>name</em>').  (Ruby).
521 </ul>
522
523 <ul>
524 <li>810. No jni typemap defined for <em>type</em>  (Java).
525 <li>811. No jtype typemap defined for <em>type</em>  (Java).
526 <li>812. No jstype typemap defined for <em>type</em>  (Java).
527 <li>813. Warning for <em>classname</em>: Base <em>baseclass</em> ignored. Multiple inheritance is not supported in Java.   (Java).
528 <li>814. 
529 <li>815. No javafinalize typemap defined for <em>type</em>  (Java).
530 <li>816. No javabody typemap defined for <em>type</em>  (Java).
531 <li>817. No javaout typemap defined for <em>type</em>  (Java).
532 <li>818. No javain typemap defined for <em>type</em>  (Java).
533 <li>819. No javadirectorin typemap defined for <em>type</em>  (Java).
534 <li>820. No javadirectorout typemap defined for <em>type</em>  (Java).
535 <li>821. 
536 <li>822. Covariant return types not supported in Java. Proxy method will return <em>basetype</em>  (Java).
537 <li>823. No javaconstruct typemap defined for <em>type</em>  (Java).
538 <li>824. Missing JNI descriptor in directorin typemap defined for <em>type</em> (Java).
539 </ul>
540
541 <ul>
542 <li>830. No ctype typemap defined for <em>type</em>  (C#).
543 <li>831. No cstype typemap defined for <em>type</em>  (C#).
544 <li>832. No cswtype typemap defined for <em>type</em>  (C#).
545 <li>833. Warning for <em>classname</em>: Base <em>baseclass</em> ignored. Multiple inheritance is not supported in C#.   (C#).
546 <li>834. 
547 <li>835. No csfinalize typemap defined for <em>type</em>  (C#).
548 <li>836. No csbody typemap defined for <em>type</em>  (C#).
549 <li>837. No csout typemap defined for <em>type</em>  (C#).
550 <li>838. No csin typemap defined for <em>type</em>  (C#).
551 <li>839. 
552 <li>840. 
553 <li>841. 
554 <li>842. Covariant return types not supported in C#. Proxy method will return <em>basetype</em>  (C#).
555 <li>843. No csconstruct typemap defined for <em>type</em>  (C#).
556 <li>844. C# exception may not be thrown - no $excode or excode attribute in <em>typemap</em> typemap. (C#).
557 <li>845. Unmanaged code contains a call to a SWIG_CSharpSetPendingException method and C# code does not handle pending exceptions via the canthrow attribute. (C#).
558 </ul>
559
560 <ul>
561 <li>870. Warning for <em>classname</em>: Base <em>baseclass</em> ignored. Multiple inheritance is not supported in PHP.
562 <li>871. Unrecognized pragma <em>pragma</em>.   (Php).
563 </ul>
564
565 <H3><a name="Warnings_nn16"></a>14.9.7 User defined (900-999)</H3>
566
567
568 <p>
569 These numbers can be used by your own application.
570 </p>
571
572 <H2><a name="Warnings_nn17"></a>14.10 History</H2>
573
574
575 <p>
576 The ability to control warning messages was first added to SWIG-1.3.12.
577 </p>
578
579 </body>
580 </html>