Menu

#682 [java] bad code generation for typedef'd enums

None
closed-duplicate
5
2024-09-04
2006-05-16
No

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.

Discussion

  • Steven K. Sharp

    Steven K. Sharp - 2006-05-16

    include and i files for enum bug.

     
  • Steven K. Sharp

    Steven K. Sharp - 2006-05-16

    Logged In: YES
    user_id=1434579

    This bug is using the trunk (pre-1.3.30?) version of SWIG.

     
  • Olly Betts

    Olly Betts - 2010-06-05
    • summary: bad code generation for typedef'd enums --> [java] bad code generation for typedef'd enums
    • assigned_to: nobody --> wsfulton
    • labels: --> java
     
  • Olly Betts

    Olly Betts - 2010-06-05

    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.

     
  • ganc

    ganc - 2014-07-08

    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.

     
  • Olly Betts

    Olly Betts - 2022-03-14
    • labels: java --> java, extra-enum
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2022-03-14

    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:

            std::cout << "woof is " << woof << std::cout;
    
     
  • Olly Betts

    Olly Betts - 2024-02-14

    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.

    I notice the type info entry includes enum baz * which seems wrong too.

     
  • Olly Betts

    Olly Betts - 2024-02-14

    Looks like https://github.com/swig/swig/issues/197 may be the same issue.

     
  • Olly Betts

    Olly Betts - 2024-09-04
    • status: open --> closed-duplicate
     
  • Olly Betts

    Olly Betts - 2024-09-04
     

Log in to post a comment.

MongoDB Logo MongoDB