简体   繁体   中英

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

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

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.

Your compiler is right to complain. It is a bug in Eigen.

Header: eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h

The template declaration,

TensorStorage.h:34

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

While, definition does not specialize anything further on the above declaration,

TensorStorage.h:38,39

template<typename T, int Options_, typename FixedDimensions>
class TensorStorage<T, FixedDimensions, Options_>
{

The fix is obvious,

TensorStorage.h:38,39

Old:

- template<typename T, int Options_, typename FixedDimensions>
- class TensorStorage<T, FixedDimensions, Options_>
  {

New:

+ template<typename T, typename FixedDimensions, int Options_>      // swap the templ params to match the declaration
+ class TensorStorage                                               // drop the specialization (because it didn't!)
  {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM