PageRenderTime 87ms CodeModel.GetById 72ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Doc/Manual/Warnings.html

#
HTML | 595 lines | 492 code | 101 blank | 2 comment | 0 complexity | 06e34ba081b97d0c429eee1772e3b085 MD5 | raw file
  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 (700-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>
 42During compilation, SWIG may generate a variety of warning messages.  For example:
 43</p>
 44
 45<div class="shell">
 46<pre>
 47example.i:16: Warning 501: Overloaded declaration ignored.  bar(double)
 48example.i:15: Warning 501: Previous declaration is bar(int)
 49</pre>
 50</div>
 51
 52<p>
 53Typically, warning messages indicate non-fatal problems with the input
 54where the generated wrapper code will probably compile, but it may not
 55work like you expect.
 56</p>
 57
 58<H2><a name="Warnings_suppression"></a>14.2 Warning message suppression</H2>
 59
 60
 61<p>
 62All warning messages have a numeric code that is shown in the warning message itself.
 63To suppress the printing of a warning message, a number of techniques can be used.
 64First, 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>
 75Alternatively, warnings can be suppressed by inserting a special preprocessor pragma
 76into 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>
 88Finally, code-generation warnings can be disabled on a declaration by declaration basis using
 89the <tt>%warnfilter</tt> directive.  For example:
 90</p>
 91
 92<div class="code">
 93<pre>
 94%module example
 95%warnfilter(501) foo;
 96...
 97int foo(int);
 98int foo(double);              // Silently ignored.
 99</pre>
100</div>
101
102<p>
103The <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#Customization_features">%feature directive</a> section.  For example, if you wanted to
106suppress 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;
112class Object {
113public:
114   int foo(int);
115   int foo(double);      // Silently ignored
116   ...
117};
118
119class Derived : public Object {
120public:
121   int foo(int);
122   int foo(double);      // Silently ignored
123   ...
124};
125</pre>
126</div>
127
128<p>
129Warnings 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
136class Object {
137public:
138   ...                      // All 501 warnings ignored in class
139};
140</pre>
141</div>
142
143<p>
144There is no option to suppress all SWIG warning messages.  The warning messages are there
145for a reason---to tell you that something may be <em>broken</em> in
146your 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>
154Some warning messages are disabled by default and are generated only
155to 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>
166To selectively turn on extra warning messages, you can use the directives and options in the
167previous 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>
177or 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>
187or
188</p>
189
190<div class="code">
191<pre>
192%warnfilter(+309,+452) foo;
193</pre>
194</div>
195
196<p>
197Note: selective enabling of warnings with <tt>%warnfilter</tt> overrides any global settings you might have
198made using <tt>-w</tt> or <tt>#pragma</tt>.
199</p>
200
201<p>
202You 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>
212The 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>
216If you would like all warnings to appear, regardless of the warning filters used, then use the <tt>-Wall</tt> option.
217The <tt>-Wall</tt> option also turns on the extra warnings that <tt>-Wextra</tt> adds, however, it is subtely different. 
218When <tt>-Wall</tt> is used, it also disables all other warning filters, 
219that is, any warnings suppressed or added in <tt>%warnfilter</tt>, <tt>#pragma SWIG nowarn</tt> 
220or 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>
227Warning 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>
238All warning messages are optionally prefixed by the warning number to use.  If you are generating
239your own warnings, make sure you don't use numbers defined in the table at the end of this section.
240</p>
241
242<p>
243The <tt>%ignorewarn</tt> directive is the same as <tt>%ignore</tt> except that it issues a
244warning 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>
254Warning 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 usage of $1_type $1_name") blah * {
261   ...
262}
263</pre>
264</div>
265
266<p>
267In this case, the warning message will be printed whenever the typemap is actually used and the <a href="Typemaps.html#Typemaps_special_variables">special variables</a> will be expanded as appropriate, for example:
268</p>
269
270<div class="shell">
271<pre>
272example.i:23: Warning 901: You are really going to regret this usage of blah * self
273example.i:24: Warning 901: You are really going to regret this usage of blah * stuff
274</pre>
275</div>
276
277<H2><a name="Warnings_symbolic_symbols"></a>14.5 Symbolic symbols</H2>
278
279
280<p>
281The <tt>swigwarn.swg</tt> file that is installed with SWIG contains symbol constants that could also be
282used in <tt>%warnfilter</tt> and <tt>#pragma SWIG nowarn</tt>.
283For example this file contains the following line:
284</p>
285
286<div class="code">
287<pre>
288%define SWIGWARN_TYPE_UNDEFINED_CLASS 401 %enddef
289</pre>
290</div>
291
292<p>
293so <tt>SWIGWARN_TYPE_UNDEFINED_CLASS</tt> could be used instead of 401, for example:
294</p>
295
296<div class="code">
297<pre>
298#pragma SWIG nowarn=SWIGWARN_TYPE_UNDEFINED_CLASS
299</pre>
300</div>
301
302<p>
303or 
304</p>
305
306<div class="code">
307<pre>
308%warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Foo;
309</pre>
310</div>
311
312<H2><a name="Warnings_nn6"></a>14.6 Commentary</H2>
313
314
315<p>
316The ability to suppress warning messages is really only provided for
317advanced users and is not recommended in normal use.  You are advised
318to modify your interface to fix the problems highlighted by the warnings
319wherever possible instead of suppressing warnings.
320</p>
321
322<p>
323Certain types of SWIG problems are errors.  These usually arise due to
324parsing errors (bad syntax) or semantic problems for which there is
325no obvious recovery.  There is no mechanism for suppressing error
326messages.
327</p>
328
329<H2><a name="Warnings_nn7"></a>14.7 Warnings as errors</H2>
330
331
332<p>
333Warnings can be handled as errors by using the <tt>-Werror</tt> command line
334option. This will cause SWIG to exit with a non successful exit code if a
335warning is encountered.
336</p>
337
338<H2><a name="Warnings_nn8"></a>14.8 Message output format</H2>
339
340
341<p>
342The output format for both warnings and errors can be selected for
343integration with your favourite IDE/editor. Editors and IDEs can usually parse 
344error messages and if in the appropriate format will easily take you 
345directly to the source of the error. The standard format is used by 
346default except on Windows where the Microsoft format is used by default.
347These can be overridden using command line options, for example:
348</p>
349
350<div class="shell"><pre>
351$ swig -python -Fstandard example.i
352example.i:4: Syntax error in input.
353$ swig -python -Fmicrosoft example.i
354example.i(4) : Syntax error in input.
355</pre></div>
356
357<H2><a name="Warnings_nn9"></a>14.9 Warning number reference</H2>
358
359
360<H3><a name="Warnings_nn10"></a>14.9.1 Deprecated features (100-199)</H3>
361
362
363<ul>
364<li>101. Deprecated <tt>%extern</tt> directive.
365<li>102. Deprecated <tt>%val</tt> directive.
366<li>103. Deprecated <tt>%out</tt> directive.
367<li>104. Deprecated <tt>%disabledoc</tt> directive.
368<li>105. Deprecated <tt>%enabledoc</tt> directive.
369<li>106. Deprecated <tt>%doconly</tt> directive.
370<li>107. Deprecated <tt>%style</tt> directive.
371<li>108. Deprecated <tt>%localstyle</tt> directive.
372<li>109. Deprecated <tt>%title</tt> directive.
373<li>110. Deprecated <tt>%section</tt> directive.
374<li>111. Deprecated <tt>%subsection</tt> directive.
375<li>112. Deprecated <tt>%subsubsection</tt> directive.
376<li>113. Deprecated <tt>%addmethods</tt> directive.
377<li>114. Deprecated <tt>%readonly</tt> directive.
378<li>115. Deprecated <tt>%readwrite</tt> directive.
379<li>116. Deprecated <tt>%except</tt> directive.
380<li>117. Deprecated <tt>%new</tt> directive.
381<li>118. Deprecated <tt>%typemap(except)</tt>.
382<li>119. Deprecated <tt>%typemap(ignore)</tt>.
383<li>120. Deprecated command line option (-runtime, -noruntime).
384<li>121. Deprecated <tt>%name</tt> directive.
385</ul>
386
387<H3><a name="Warnings_nn11"></a>14.9.2 Preprocessor (200-299)</H3>
388
389
390<ul>
391<li>201. Unable to find <em>filename</em>.
392<li>202. Could not evaluate expression <em>expr</em>.
393<li>203. Both includeall and importall are defined: using includeall.
394<li>204. CPP #warning, "<em>warning</em>".
395<li>205. CPP #error, "<em>error</em>".
396<li>206. Unexpected tokens after #<em>directive</em> directive.
397</ul>
398
399<H3><a name="Warnings_nn12"></a>14.9.3 C/C++ Parser (300-399)</H3>
400
401
402<ul>
403<li>301. <tt>class</tt> keyword used, but not in C++ mode.
404<li>302. Identifier '<em>name</em>' redefined (ignored).
405<li>303. <tt>%extend</tt> defined for an undeclared class '<em>name</em>'.
406<li>304. Unsupported constant value (ignored).
407<li>305. Bad constant value (ignored).
408<li>306. '<em>identifier</em>' is private in this context.
409<li>307. Can't set default argument value (ignored)
410<li>308. Namespace alias '<em>name</em>' not allowed here. Assuming '<em>name</em>'
411<li>309. [private | protected] inheritance ignored.
412<li>310. Template '<em>name</em>' was already wrapped as '<em>name</em>' (ignored)
413<li>312. Unnamed nested class not currently supported (ignored).
414<li>313. Unrecognized extern type "<em>name</em>" (ignored).
415<li>314. '<em>identifier</em>' is a <em>lang</em> keyword.
416<li>315. Nothing known about '<em>identifier</em>'.
417<li>316. Repeated %module directive.
418<li>317. Specialization of non-template '<em>name</em>'.
419<li>318. Instantiation of template '<em>name</em>' is ambiguous, instantiation <em>templ</em> used, instantiation <em>templ</em> ignored.
420<li>319. No access specifier given for base class <em>name</em> (ignored).
421<li>320. Explicit template instantiation ignored.
422<li>321. <em>identifier</em> conflicts with a built-in name.
423<li>322. Redundant redeclaration of '<em>name</em>'.
424<li>323. Recursive scope inheritance of '<em>name</em>'.
425<li>324. Named nested template instantiations not supported. Processing as if no name was given to %template().
426<li>325. Nested class not currently supported (<em>name</em> ignored).
427<li>350. operator new ignored.
428<li>351. operator delete ignored.
429<li>352. operator+ ignored.
430<li>353. operator- ignored.
431<li>354. operator* ignored.
432<li>355. operator/ ignored.
433<li>356. operator% ignored.
434<li>357. operator^ ignored.
435<li>358. operator&amp; ignored.
436<li>359. operator| ignored.
437<li>360. operator~ ignored.
438<li>361. operator! ignored.
439<li>362. operator= ignored.
440<li>363. operator&lt; ignored.
441<li>364. operator&gt; ignored.
442<li>365. operator+= ignored.
443<li>366. operator-= ignored.
444<li>367. operator*= ignored.
445<li>368. operator/= ignored.
446<li>369. operator%= ignored.
447<li>370. operator^= ignored.
448<li>371. operator&amp;= ignored.
449<li>372. operator|= ignored.
450<li>373. operator&lt;&lt; ignored.
451<li>374. operator&gt;&gt;ignored.
452<li>375. operator&lt;&lt;= ignored.
453<li>376. operator&gt;&gt;= ignored.
454<li>377. operator== ignored.
455<li>378. operator!= ignored.
456<li>379. operator&lt;= ignored.
457<li>380. operator&gt;= ignored.
458<li>381. operator&amp;&amp; ignored.
459<li>382. operator|| ignored.
460<li>383. operator++ ignored.
461<li>384. operator-- ignored.
462<li>385. operator, ignored.
463<li>386. operator-&lt;* ignored.
464<li>387. operator-&lt; ignored.
465<li>388. operator() ignored.
466<li>389. operator[] ignored.
467<li>390. operator+ ignored (unary).
468<li>391. operator- ignored (unary).
469<li>392. operator* ignored (unary).
470<li>393. operator&amp; ignored (unary).
471<li>394. operator new[] ignored.
472<li>395. operator delete[] ignored.
473</ul>
474
475<H3><a name="Warnings_nn13"></a>14.9.4 Types and typemaps (400-499) </H3>
476
477
478<ul>
479<li>401. Nothing known about class 'name'. Ignored.
480<li>402. Base class 'name' is incomplete.
481<li>403. Class 'name' might be abstract.
482<li>450. Deprecated typemap feature ($source/$target).
483<li>451. Setting const char * variable may leak memory.
484<li>452. Reserved
485<li>453. Can't apply (pattern). No typemaps are defined.
486<li>460. Unable to use type <em>type</em> as a function argument.
487<li>461. Unable to use return type <em>type</em> in function <em>name</em>.
488<li>462. Unable to set variable of type <em>type</em>.
489<li>463. Unable to read variable of type <em>type</em>.
490<li>464. Unsupported constant value.
491<li>465. Unable to handle type <em>type</em>.
492<li>466. Unsupported variable type <em>type</em>.
493<li>467. Overloaded <em>declaration</em> not supported (no type checking rule for '<em>type</em>')
494<li>468. No 'throw' typemap defined for exception type <em>type</em>
495<li>469. No or improper directorin typemap defined for <em>type</em>
496<li>470. Thread/reentrant unsafe wrapping, consider returning by value instead.
497<li>471. Unable to use return type <em>type</em> in director method
498<li>474. Method <em>method</em> usage of the optimal attribute ignored in the out typemap as the following cannot be used to generate optimal code: <em>code</em>
499<li>475. Multiple calls to <em>method</em> might be generated due to optimal attribute usage in the out typemap.
500</ul>
501
502
503
504<H3><a name="Warnings_nn14"></a>14.9.5 Code generation (500-599)</H3>
505
506
507<ul>
508<li>501. Overloaded declaration ignored. <em>decl</em>. Previous declaration is <em>decl</em>.
509<li>502. Overloaded constructor ignored. <em>decl</em>. Previous declaration is <em>decl</em>.
510<li>503. Can't wrap '<em>identifier</em>' unless renamed to a valid identifier.
511<li>504. Function <em>name</em> must have a return type. Ignored.
512<li>505. Variable length arguments discarded.
513<li>506. Can't wrap varargs with keyword arguments enabled.
514<li>507. Adding native function <em>name</em> not supported (ignored).
515<li>508. Declaration of '<em>name</em>' shadows declaration accessible via operator-&gt;(), previous declaration of'<em>declaration</em>'.
516<li>509. Overloaded method <em>declaration</em> effectively ignored, as it is shadowed by <em>declaration</em>.
517<li>510. Friend function '<em>name</em>' ignored.
518<li>511. Can't use keyword arguments with overloaded functions.
519<li>512. Overloaded method <em>declaration</em> ignored, using non-const method <em>declaration</em> instead.
520<li>513. Can't generate wrappers for unnamed struct/class.
521<li>514. 
522<li>515. 
523<li>516. Overloaded method <em>declaration</em> ignored, using <em>declaration</em> instead.
524<li>517. 
525<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.
526<li>519. %template() contains no name. Template method ignored: <em>declaration</em>
527<li>520. <em>Base/Derived</em> class '<em>classname1</em>' of '<em>classname2</em>' is not similarly marked as a smart pointer.
528<li>521. Illegal destructor name <em>name</em>. Ignored.
529</ul>
530
531<H3><a name="Warnings_nn15"></a>14.9.6 Language module specific (700-899) </H3>
532
533
534<ul>
535<li>801. Wrong name (corrected to '<em>name</em>').  (Ruby).
536</ul>
537
538<ul>
539<li>810. No jni typemap defined for <em>type</em>  (Java).
540<li>811. No jtype typemap defined for <em>type</em>  (Java).
541<li>812. No jstype typemap defined for <em>type</em>  (Java).
542<li>813. Warning for <em>classname</em>: Base <em>baseclass</em> ignored. Multiple inheritance is not supported in Java.   (Java).
543<li>814. 
544<li>815. No javafinalize typemap defined for <em>type</em>  (Java).
545<li>816. No javabody typemap defined for <em>type</em>  (Java).
546<li>817. No javaout typemap defined for <em>type</em>  (Java).
547<li>818. No javain typemap defined for <em>type</em>  (Java).
548<li>819. No javadirectorin typemap defined for <em>type</em>  (Java).
549<li>820. No javadirectorout typemap defined for <em>type</em>  (Java).
550<li>821. 
551<li>822. Covariant return types not supported in Java. Proxy method will return <em>basetype</em>  (Java).
552<li>823. No javaconstruct typemap defined for <em>type</em>  (Java).
553<li>824. Missing JNI descriptor in directorin typemap defined for <em>type</em> (Java).
554</ul>
555
556<ul>
557<li>830. No ctype typemap defined for <em>type</em>  (C#).
558<li>831. No cstype typemap defined for <em>type</em>  (C#).
559<li>832. No cswtype typemap defined for <em>type</em>  (C#).
560<li>833. Warning for <em>classname</em>: Base <em>baseclass</em> ignored. Multiple inheritance is not supported in C#.   (C#).
561<li>834. 
562<li>835. No csfinalize typemap defined for <em>type</em>  (C#).
563<li>836. No csbody typemap defined for <em>type</em>  (C#).
564<li>837. No csout typemap defined for <em>type</em>  (C#).
565<li>838. No csin typemap defined for <em>type</em>  (C#).
566<li>839. 
567<li>840. 
568<li>841. 
569<li>842. Covariant return types not supported in C#. Proxy method will return <em>basetype</em>  (C#).
570<li>843. No csconstruct typemap defined for <em>type</em>  (C#).
571<li>844. C# exception may not be thrown - no $excode or excode attribute in <em>typemap</em> typemap. (C#).
572<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#).
573</ul>
574
575<ul>
576<li>870. Warning for <em>classname</em>: Base <em>baseclass</em> ignored. Multiple inheritance is not supported in PHP.
577<li>871. Unrecognized pragma <em>pragma</em>.   (Php).
578</ul>
579
580<H3><a name="Warnings_nn16"></a>14.9.7 User defined (900-999)</H3>
581
582
583<p>
584These numbers can be used by your own application.
585</p>
586
587<H2><a name="Warnings_nn17"></a>14.10 History</H2>
588
589
590<p>
591The ability to control warning messages was first added to SWIG-1.3.12.
592</p>
593
594</body>
595</html>