I have a problem of substitution failure, and answers of some similar questions do not help me.
Here is the code:
template<int dim, int loop>
class Reference{
public:
//...
template<int r, int c> using matrix_t = int[r][c];
Reference(const matrix_t<dim, loop> &mat){}
};
template<int dim, int loop>
class Partition{
// ...
public:
// ...
template<int r, int c> using matrix = int[r][c];
template<int r, int c> void readPattern(const matrix<r,c> &pattern)
{
// ...
}
// ...
};
And I call this template function like so:
int main()
{
// ...
const int DENOISE_UR[3][4] = {/*...*/};
Partition<1,2> partition;
partition.readPattern(DENOISE_UR);
// ...
}
Using g++, it compiles.
When using clang++(linux) to compile(clang++ -std=c++11 xxx.cpp
), it resulted in the following compiling error:
error: no matching function for call to 'readPattern'
note: candidate template ignored: substitution failure[ with r = 3, c = 4 ]
template<int r, int c> void readPattern(const matrix<r,c> &pattern)
Why?
It's a bug in clang; it misbehaves when an alias template defining an array type is defined within a class template. In fact it can be exploited to crash the compiler:
Since in your case
Reference::matrix_t
does not depend on the template arguments toReference
, the simplest workaround would be to move the definition ofmatrix_t
to namespace scope:In fact, you don't even need to use
impl::matrix_t
to workaround the bug:This is now fixed (the fix should be in clang release version 3.8.0):