Xcode 9 falls to build partial template specialization in c++

Viewed 1245

I update my Xcode to version 9 and fall to build my app containing Tensorflow framework. It seems that the following code:

#ifndef Header_h
#define Header_h
template<class T1, class T2, int I> class A {}; // primary template

template<class T1, int I, class T2> class A<T1, T2, I> {};  //error
#endif /* Header_h */

will be rejected by Xcode 9 with error message "Partial template specialization is not more specialized than primary template". But in Xcode 8.3.3 and visual studio, it is good.

Here is the original Tensorflow code: (TensorStorage.h)

template<typename T, typename Dimensions, int Options_> class TensorStorage;


// Pure fixed-size storage
template<typename T, int Options_, typename FixedDimensions>
class TensorStorage<T, FixedDimensions, Options_>
{
    //implementation
};

// pure dynamic
template<typename T, int Options_, typename IndexType, int NumIndices_>
class TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_>
{
    //implementation
};

Thanks

3 Answers

This gave me another error message. I found another solution that worked as well:

I changed line 34 in TensorStorage.h from

template<typename T, typename Dimensions, int Options_> class TensorStorage;

to

template<typename T, typename Dimensions, int Options_, typename empty = void> class TensorStorage;

I come to answer my own question now. I think it maybe the compiler's issue. I have already sent Technical Support Incident to apple, but currently I find some dirty solution. Change the original code:

template<typename T, typename Dimensions, int Options_> class TensorStorage;
// Pure fixed-size storage
template<typename T, int Options_, typename FixedDimensions>
class TensorStorage<T, FixedDimensions, Options_>
{
    //implementation
};

// pure dynamic
template<typename T, int Options_, typename IndexType, int NumIndices_>
class TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_>
{
    //implementation
};

To:

template<typename T, typename FixedDimensions, int Options_> //class TensorStorage;
// Pure fixed-size storage
//template<typename T, int Options_, typename FixedDimensions>
class TensorStorage//<T, FixedDimensions, Options_>
{
    //implementation
};

// pure dynamic
template<typename T, int Options_, typename IndexType, int NumIndices_>
class TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_>
{
    //implementation
};

The code is dirty now, but it works. Just let the first implementation to be explicit primary template. I'll wait for apple's reply.

Related