The code generated for typedef enum { blah = 1, bleh } baz;
is incorrect. In a call that takes a baz as an argument results in "enum baz" in the cast instead of just "baz".
Attached is an example that demonstrates the bug.
include and i files for enum bug.
Logged In: YES user_id=1434579
This bug is using the trunk (pre-1.3.30?) version of SWIG.
Setting category to Java, and assigning to William as the SWIG/Java maintainer.
Reproducible with trunk shortly after SWIG 2.0.0.
Needs to be processed with: swig -java -c++
Problematic line is now:
foo2::bar2::enumbugexample((enum foo::bar::baz const &)*arg1);
Removing "enum" allows this to compile.
Essentially the same problem is still present in SWIG 3.0.2, swig -csharp -c++
typedef enum { RED = 1, BLUE, GREEN } MyEnum;
There is an extra "enum" before the name on some but not all occasions, resulting in casting errors. Removing the keyword allows compilation.
Still broken with git master with the same bad code generated. Testing with:
../preinst-swig -c++ -java enumbug2.i g++ -fPIC -shared -I"/usr/lib/jvm/java-1.10.0-openjdk-amd64/include" -I"/usr/lib/jvm/java-1.10.0-openjdk-amd64/include/linux" enumbug2_wrap.cxx enumbug2.cpp -o libenumbug2.so
This is not the cause of the problem, but I noticed enumbug2.cpp in the supplied testcase needs a fix - change the second cout here to endl:
enumbug2.cpp
cout
endl
std::cout << "woof is " << woof << std::cout;
Still reproducible with current git master. Also I came up with a much simpler reproducer:
%module x %inline %{ typedef enum { BAZ1 } baz; void enumbugexample( baz const & ) { } %}
Then:
$ swig -c++ -python simplified.i $ grep 'enum baz' simplified_wrap.cxx enumbugexample((enum baz const &)*arg1); static swig_type_info _swigt__p_baz = {"_p_baz", "baz *|enum baz *", 0, 0, (void*)0, 0};
The const & seems to be needed.
const &
I notice the type info entry includes enum baz * which seems wrong too.
enum baz *
Looks like https://github.com/swig/swig/issues/197 may be the same issue.
Closing in favour of https://github.com/swig/swig/issues/3012
Log in to post a comment.
include and i files for enum bug.
Logged In: YES
user_id=1434579
This bug is using the trunk (pre-1.3.30?) version of SWIG.
Setting category to Java, and assigning to William as the SWIG/Java maintainer.
Reproducible with trunk shortly after SWIG 2.0.0.
Needs to be processed with: swig -java -c++
Problematic line is now:
foo2::bar2::enumbugexample((enum foo::bar::baz const &)*arg1);
Removing "enum" allows this to compile.
Essentially the same problem is still present in SWIG 3.0.2, swig -csharp -c++
There is an extra "enum" before the name on some but not all occasions, resulting in casting errors. Removing the keyword allows compilation.
Still broken with git master with the same bad code generated. Testing with:
This is not the cause of the problem, but I noticed
enumbug2.cppin the supplied testcase needs a fix - change the secondcouthere toendl:Still reproducible with current git master. Also I came up with a much simpler reproducer:
Then:
The
const &seems to be needed.I notice the type info entry includes
enum baz *which seems wrong too.Looks like https://github.com/swig/swig/issues/197 may be the same issue.
Closing in favour of https://github.com/swig/swig/issues/3012