Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dbankieris opened this issue Apr 30, 2024 · 3 comments · Fixed by #1741
Closed

Comments

@dbankieris
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

hchen99 commented May 2, 2024

Thanks for reporting. We'll look into this.

@sharmeye sharmeye linked a pull request Jul 23, 2024 that will close this issue
@sharmeye
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants