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

Explicit specialization error when using uint8_t type in template pair interface #2274

Open
msclissa opened this issue May 5, 2022 · 1 comment
Labels

Comments

@msclissa
Copy link

msclissa commented May 5, 2022

I'm hoping there's something simple to work around this that I'm missing, but I haven't been able to figure it out.

We're building a Python interface for a C++ project and have the following typedefs:

namespace mscl
{
  typedef std::uint8_t uint8;
  enum EnumIdentifier {};
  enum EnumCategory {};

  typedef std::pair<EnumIdentifier, uint8> PairType;
  typedef std::vector<PairType> Vector_PairType;
  typedef std::map<EnumCategory, Vector_PairType> Map_Vector_PairType;
}

In our interface file (.i) we have the following template definitions:

%template(PairType)             pair<mscl::EnumIdentifier, uint8_t>;
%template(Vector_PairType)      vector<pair<mscl::EnumIdentifier, uint8_t>>;
%template(Map_Vector_PairType)  map<enum mscl::EnumCategory, vector<pair<mscl::EnumIdentifier, uint8_t>>>;

We successfully use a similar pattern for other templated collection types but for this one the uint8_t seems to be giving us trouble. On build I get the error:

explicit specialization; 'swig::traits<std::pair<mscl::EnumIdentifier,mscl::uint8>>' has already been defined

and the generated wrap.cxx file contains a pair trait definition for both uint8_t and unsigned char:

namespace swig {
  template <>  struct traits<std::pair< mscl::EnumIdentifier, unsigned char > > {
    typedef pointer_category category;
    static const char* type_name() {
      return "std::pair<" "mscl::EnumIdentifier" "," "unsigned char" " >";
    }
  };
}

namespace swig {
  template <>  struct traits< std::pair< mscl::EnumIdentifier,uint8_t > > {
    typedef pointer_category category;
    static const char* type_name() { return"std::pair< mscl::EnumIdentifier,uint8_t >"; }
  };
}

I tried switching uint8_t to unsigned char in the template definitions, but that resulted in a bunch of unresolved externals. Switching uint8_t to uint16_t resulted in the same as the initial issue, but with unsigned short in the first generated traits def.

In case it's relevant, the same .i file was used to generate a .NET interface without issue. The actual .i file can be found here (ln 296-8).

What am I missing? Let me know if you need any clarification or additional information - thanks!

@ojwb
Copy link
Member

ojwb commented Jun 11, 2022

I'd try explicitly std:: qualifying the things which are from the std namespace in the %template directives - ISTR there a problem with resolve such cases.

If it's not that, a small, self-contained reproducer would be helpful.

@ojwb ojwb added the C++ label Jun 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants