duplicate symbol in clang for template specialization of static member

23 views Asked by At

I created a template that contains some static members, everything compile and run on visual studio, but I got a link error when using clang++ inside android studio

ld: error: duplicate symbol: namespace::RotatedIndexing<unsigned int, (unsigned char)8, (unsigned char)8, (unsigned char)32>::s_flipDiag

template<typename TMASK, uint8_t A, uint8_t B, uint8_t USEDSQUARES>
class RotatedIndexing
{
  //....
  static const std::array<uint16_t, USEDSQUARES> s_flipDiag;
};


//not specialized template
template<typename TMASK, uint8_t ROWS, uint8_t COLS, uint8_t USEDSQUARES>
const std::array<uint16_t, USEDSQUARES> RotatedIndexing<TMASK, ROWS, COLS, USEDSQUARES>::s_flipDiag = { 0 };

//specialization 1
template<> const std::array<uint16_t, 32> RotatedIndexing<uint32_t, 8, 8, 32>::s_flipDiag =
{ 27,19,11,3, 31,23,15,7, 26,18,10,2, 30,22,14,6, 25,17,9,1, 29,21,13,5, 24,16,8,0, 28,20,12,4 };

//specialization 2
template<> const std::array<uint16_t, 50> RotatedIndexing<uint64_t, 10, 10, 50>::s_flipDiag =
{ 44,34,24,14,4, 49,39,29,19,9, 43,33,23,13,3, 48,38,28,18,8, 42,32,22,12,2, 47,37,27,17,7, 41,31,21,11,1, 46,36,26,16,6, 40,30,20,10,0, 45,35,25,15,5 };

Am I doing anything wrong here? If I do not use the template specializations, clang compiles it without issues. Possibly is there something in the standard that clang follows more strictly than visual studio?

I tried to move the specializations to a cpp file (as for a normal static members of a non-template class), but I got lot of compilation errors in other files when instantiating an object of that class (also with visual studio).

0

There are 0 answers