Menu

#852 False name collision between overloaded functions

None
open
nobody
parsing (146)
5
2024-01-29
2007-09-13
No

Give SWIG 1.3.31 this:

void f();
namespace N {
    void f(int);
}

1>swig.i(60): Error: 'f' is multiply defined in the generated module.
1>swig.i(58): Error: Previous declaration of 'f'

It shouldn't happen since they have different arguments.

Discussion

  • Olly Betts

    Olly Betts - 2010-05-26
    • labels: --> parsing
     
  • Olly Betts

    Olly Betts - 2010-05-26

    Still present with trunk shortly before 2.0.0.

     
  • Olly Betts

    Olly Betts - 2022-02-01

    Still present with current git master.

     
  • Olly Betts

    Olly Betts - 2022-02-15
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,9 +1,9 @@
     Give SWIG 1.3.31 this:
    
    -   void f\(\);
    -   namespace N \{
    -       void f\(int\);
    -   \}
    +   void f();
    +   namespace N {
    +       void f(int);
    +   }
    
     1>swig.i\(60\): Error: 'f' is multiply defined in the generated module.
     1>swig.i\(58\): Error: Previous declaration of 'f'
    
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2024-01-25

    Still present in git shortly after 4.2.0.

    It also seems to fail even if %nspace N; is used with a target language with %nspace support.

     
  • Olly Betts

    Olly Betts - 2024-01-29

    I noticed the problem reported here is actually documented in the manual:

    https://www.swig.org/Doc4.2/SWIGPlus.html#SWIGPlus_namespaces

    Because namespaces are flattened, it is possible for symbols defined in different namespaces to generate a name conflict in the target language. For example:
    
    namespace A {
      void foo(int);
    }
    namespace B {
      void foo(double);
    }
    
    When this conflict occurs, you will get an error message that resembles this:
    
    example.i:26. Error. 'foo' is multiply defined in the generated target language module.
    example.i:23. Previous declaration of 'foo'
    

    However this still seems like a bug to me (it'd be nicer to handle this as an overload, like would happen if the namespaces just weren't there). It especially seems wrong that the collision still happens if %nspace is used.

     

Log in to post a comment.