Warning Messages

# 11 Warning Messages

- Introduction
- Warning message suppression
- Enabling additional warnings
- Issuing a warning message
- Commentary
- Warning number reference
  - Deprecated features (100-199)
  - Preprocessor (200-299)
  - C/C++ Parser (300-399)
  - Types and typemaps (400-499)
  - Code generation (500-599)
  - Language module specific (800-899)
  - User defined (900-999)
- History

## 11.1 Introduction

During compilation, SWIG may generate a variety of warning messages. For example:

>     example.i:16: Warning(501): Overloaded declaration ignored.  bar(double)
>     example.i:15: Warning(501): Previous declaration is bar(int)

Typically, warning messages indicate non-fatal problems with the input where the generated wrapper code will probably compile, but it may not work like you expect.

## 11.2 Warning message suppression

All warning messages have a numeric code that is shown in the warning message itself. To suppress the printing of a warning message, a number of techniques can be used. First, you can run SWIG with the `-w` command line option. For example:

>     % swig -python -w501 example.i
>     % swig -python -w501,505,401 example.i

Alternatively, warnings can be suppressed by inserting a special preprocessor pragma into the input file:

>     %module example
>     #pragma SWIG nowarn=501
>     #pragma SWIG nowarn=501,505,401

Finally, code-generation warnings can be disabled on a declaration by declaration basis using the `%warnfilter` directive. For example:

>     %module example
>     %warnfilter(501) foo;
>     ...
>     int foo(int);
>     int foo(double);              // Silently ignored.

The `%warnfilter` directive has the same semantics as other declaration modifiers like `%rename`, `%ignore`, and `%feature`. For example, if you wanted to suppress a warning for a method in a class hierarchy, you could do this:

>     %warnfilter(501) Object::foo;
>     class Object {
>     public:
>        int foo(int);
>        int foo(double);      // Silently ignored
>        ...
>     };

>     class Derived : public Object {
>     public:
>        int foo(int);
>        int foo(double);      // Silently ignored
>        ...
>     };

Warnings can be suppressed for an entire class by supplying a class name. For example:

>     %warnfilter(501) Object;

>     class Object {
>     public:
>        ...                      // All 501 warnings ignored in class
>     };

There is no option to suppress all SWIG warning messages. The warning messages are there for a reason---to tell you that something may be broken in your interface. Ignore the warning messages at your own peril.

## 11.3 Enabling additional warnings

Some warning messages are disabled by default and are generated only to provide additional diagnostics. All warning messages can be enabled using the `-Wall` option. For example:

>     % swig -Wall -python example.i

When `-Wall` is used, all other warning filters are disabled.

To selectively turn on extra warning messages, you can use the directives and options in the previous section--simply add a "+" to all warning numbers. For example:

>     % swig -w+309,+452 example.i

or

>     #pragma SWIG nowarn=+309,+452

or

>     %warnfilter(+309,+452) foo;

Note: selective enabling of warnings with `%warnfilter` overrides any global settings you might have made using `-w` or `#pragma`.

## 11.4 Issuing a warning message

Warning messages can be issued from an interface file using a number of directives. The `%warn` directive is the most simple:

>     %warn "750:This is your last warning!"

All warning messages are optionally prefixed by the warning number to use. If you are generating your own warnings, make sure you don't use numbers defined in the table at the end of this section.

The `%ignorewarn` directive is the same as `%ignore` except that it issues a warning message whenever a matching declaration is found. For example:

>     %ignorewarn("362:operator= ignored") operator=;

Warning messages can be associated with typemaps using the `warning` attribute of a typemap declaration. For example:

>     %typemap(in, warning="751:You are really going to regret this") blah * {
>        ...
>     }

In this case, the warning message will be printed whenever the typemap is actually used.

## 11.5 Commentary

The ability to suppress warning messages is really only provided for advanced users and is not recommended in normal use. There are no plans to provide symbolic names or options that identify specific types or groups of warning messages---the numbers must be used explicitly.

Certain types of SWIG problems are errors. These usually arise due to parsing errors (bad syntax) or semantic problems for which there is no obvious recovery. There is no mechanism for suppressing error messages or handling errors as warnings---you must make changes to the input file to fix the problem.

## 11.6 Warning number reference

### 11.6.1 Deprecated features (100-199)

- 101. Deprecated `%extern` directive.
- 102. Deprecated `%val` directive.
- 103. Deprecated `%out` directive.
- 104. Deprecated `%disabledoc` directive.
- 105. Deprecated `%enabledoc` directive.
- 106. Deprecated `%doconly` directive.
- 107. Deprecated `%style` directive.
- 108. Deprecated `%localstyle` directive.
- 109. Deprecated `%title` directive.
- 110. Deprecated `%section` directive.
- 111. Deprecated `%subsection` directive.
- 112. Deprecated `%subsubsection` directive.
- 113. Deprecated `%addmethods` directive.
- 114. Deprecated `%readonly` directive.
- 115. Deprecated `%readwrite` directive.
- 116. Deprecated `%except` directive.
- 117. Deprecated `%new` directive.
- 118. Deprecated `%typemap(except)`.

### 11.6.2 Preprocessor (200-299)

- 201. Unable to find 'filename'.
- 202. Could not evaluate 'expr'.

### 11.6.3 C/C++ Parser (300-399)

- 301. `class` keyword used, but not in C++ mode.
- 302. Identifier 'name' redeclared (ignored).
- 303. `%extend` defined for an undeclared class 'name'.
- 304. Unsupported constant value (ignored).
- 305. Bad constant value (ignored).
- 306. 'identifier' is private in this context.
- 307. Can't set default argument value (ignored)
- 308. Namespace alias 'name' not allowed here. Assuming 'name'
- 309. [private | protected] inheritance ignored.
- 310. Template 'name' was already wrapped as 'name' (ignored)
- 311. Template partial specialization not supported.
- 312. Nested classes not currently supported (ignored).
- 313. Unrecognized extern type "name" (ignored).
- 314. 'identifier' is a lang keyword.
- 315. Nothing known about 'identifier'.
- 316. Repeated %module directive.
- 317. Specialization of non-template 'name'.
- 318. Instantiation of template name is ambiguous. Using templ at file:line
- 319. No access specifier given for base class name (ignored).
- 350. operator new ignored.
- 351. operator delete ignored.
- 352. operator+ ignored.
- 353. operator- ignored.
- 354. operator* ignored.
- 355. operator/ ignored.
- 356. operator% ignored.
- 357. operator^ ignored.
- 358. operator& ignored.
- 359. operator| ignored.
- 360. operator~ ignored.
- 361. operator! ignored.
- 362. operator= ignored.
- 363. operator< ignored.
- 364. operator> ignored.
- 365. operator+= ignored.
- 366. operator-= ignored.
- 367. operator*= ignored.
- 368. operator/= ignored.
- 369. operator%= ignored.
- 370. operator^= ignored.
- 371. operator&= ignored.
- 372. operator|= ignored.
- 373. operator<< ignored.
- 374. operator>>ignored.
- 375. operator<<= ignored.
- 376. operator>>= ignored.
- 377. operator== ignored.
- 378. operator!= ignored.
- 379. operator<= ignored.
- 380. operator>= ignored.
- 381. operator&& ignored.
- 382. operator|| ignored.
- 383. operator++ ignored.
- 384. operator-- ignored.
- 385. operator, ignored.
- 386. operator-<* ignored.
- 387. operator-< ignored.
- 388. operator() ignored.
- 389. operator[] ignored.
- 390. operator+ ignored (unary).
- 391. operator- ignored (unary).
- 392. operator* ignored (unary).
- 393. operator& ignored (unary).
- 394. operator new[] ignored.
- 395. operator delete[] ignored.

### 11.6.4 Types and typemaps (400-499)

- 401. Nothing known about class 'name'. Ignored.
- 402. Base class 'name' is incomplete.
- 403. Class 'name' might be abstract.
- 450. Deprecated typemap feature ($source/$target).
- 451. Setting const char * variable may leak memory.
- 452. Reserved
- 453. Can't apply (pattern). No typemaps are defined.
- 460. Unable to use type type as a function argument.
- 461. Unable to use return type type in function name.
- 462. Unable to set variable of type type.
- 463. Unable to read variable of type type.
- 464. Unsupported constant value.
- 465. Unable to handle type type.
- 466. Unsupported variable type type.
- 467. Overloaded declaration not supported (no type checking rule for 'type')
- 468. No 'throw' typemap defined for exception type 'type'.

### 11.6.5 Code generation (500-599)

- 501. Overloaded declaration ignored. decl
- 502. Overloaded constructor ignored. decl
- 503. Can't wrap 'identifier' unless renamed to a valid identifier.
- 504. Function name must have a return type.
- 505. Variable length arguments discarded.
- 506. Can't wrap varargs with keyword arguments enabled.
- 507. Adding native function name not supported (ignored).
- 508. Declaration of 'name' shadows declaration accessible via operator->() at file:line.
- 509. Overloaded declaration is shadowed by declaration at file:line.
- 510. Friend function 'name' ignored.
- 511. Can't use keyword arguments with overloaded functions.
- 512. Overloaded declaration const ignored. Non-const method at file:line used.
- 513. Can't generate wrappers for unnamed struct/class.

### 11.6.6 Language module specific (800-899)

- 801. Wrong name (corrected to 'name'). (Ruby).
- 810. No jni typemap defined for type (Java).
- 811. No jtype typemap defined for type (Java).
- 812. No jstype typemap defined for type (Java).
- 813. Warning for classname: Base baseclass ignored. Multiple inheritance is not supported in Java. (Java).
- 814. No javagetcptr typemap defined for type (Java).
- 815. No javafinalize typemap defined for type (Java).
- 816. No javaptrconstructormodifier typemap defined for type (Java).

### 11.6.7 User defined (900-999)

These numbers can be used by your own application.

## 11.7 History

The ability to control warning messages was first added to SWIG-1.3.12.