nasa / trick

Trick Simulation Environment. Trick provides a common set of simulation capabilities and utilities to build simulations automatically.
Other
34 stars 19 forks source link

Invalid SWIG code is generated for a template that's defined and used in the same file #1704

Closed dbankieris closed 2 months ago

dbankieris commented 5 months ago

Another problem resulting from #1679.

namespace a { 

template <class T>
class Bar {}; 

class Foo {
  public:
    Bar<int> bar;
};

}

Compiling yields Foo_py.i:21: Error: Template 'Bar' undefined.

This is due to %template being placed before the definition of Bar in Foo_py.i

#ifndef TRICK_SWIG_TEMPLATE_a__Foo_bar
#define TRICK_SWIG_TEMPLATE_a__Foo_bar
namespace a { 
%template(a__Foo_bar) Bar<int>;
}
#endif

namespace a{

template <class T>
class Bar {};
dbankieris commented 5 months ago

Also fails if the definition of Bar is outside of the a namespace, although for a different reason.

template <class T>
class Bar {}; 

namespace a { 

  class Foo {
    public:
      Bar<int> bar;
  };  

}

Compiling yields Foo_py.i:26: Error: 'Bar' resolves to '::Bar' and was incorrectly instantiated in scope 'a' instead of within scope ''.

This is due to %template being placed in the wrong namespace.

template <class T>
class Bar {}; 

#ifndef TRICK_SWIG_TEMPLATE_a__Foo_bar
#define TRICK_SWIG_TEMPLATE_a__Foo_bar
namespace a { 
%template(a__Foo_bar) Bar<int>;
}
#endif
hchen99 commented 5 months ago

Thanks for reporting. We'll look into this.

sharmeye commented 2 months ago

We think this is addressed by #1741. Closing this down.