#971 wide string parsing error

parsing (147)
Yoonsik Oh

Interface file include the header file.

The following example:

== test.i ==
%module test
#include "test.h"

%include "test.h"

== test.h ==
void foo(const char* str); // OK
void foo(const char* str = "test"); // OK
void foo(const wchar_t* str); // OK
void foo(const wchar_t* str = L"test"); //error

A fourth of the only makes an error when parsing.

I think it should be possible to parse.



  • David Piepgrass

    David Piepgrass - 2008-12-12

    This is a limitation of SWIG's parser (it doesn't understand wide strings).

    A workaround is to add "#define L" near the top of your interface file (.i).

  • William Fulton

    William Fulton - 2008-12-12

    Is this in one of the C or C++ standards, and if so which section?

  • Olly Betts

    Olly Betts - 2008-12-13

    Yes, this is standard ISO C and C++.

    For C++, "hod139" quotes the relevant section (2.13.4) here:


    I don't have my C standard here, and have failed to track down a quotation for this online, but I'm certain it's in there too.

    Setting category to "parsing" not "code generation (general)"...

  • Olly Betts

    Olly Betts - 2008-12-13
    • labels: 505206 --> parsing
  • William Fulton

    William Fulton - 2009-04-09

    #987106 is a duplicate of this bug

  • Vladimir Kalinin

    I patched the scanner to treat wide strings like normal literals, perhaps this may be of interest to someone else. (Proper fix should probably introduce a new token, but I'm not sure if it is of any use - string literals are not used in any interface wrappers, are they?)

    (git-format patch is attached)

    Last edit: Vladimir Kalinin 2013-01-04

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks