[cfe-dev] default arguments cannot be added to an out-of-line definition of a member of a class template
Jack Howarth
howarth at bromo.med.uc.edu
Tue Jul 19 07:57:45 PDT 2011
While trying to compile ccp4 with clang, I ran into the following error in the test case...
------------- outofline.cpp --------------------
template <typename realnum>
class covar_matrix
{
public:
void SetZeroRows(int,int,int,int,int,int); // specifies the order numbers of rows(=columns) for which the covariances should be 0.
private:
};
// defines zero rows. If the first argument is negative, resets all no non-zero.
template <typename realnum>
void covar_matrix<realnum>::SetZeroRows( int r1=-1, int r2=-1, int r3=-1, int r4=-1, int r5=-1, int r6=-1 )
{
int r[6] = {r1,r2,r3,r4,r5,r6};
int i=0;
}
------------------------------------------------
[MacPro:~] howarth% clang -c outofline.cpp
outofline.cpp:16:46: error: default arguments cannot be added to an out-of-line definition of a member of a class template
void covar_matrix<realnum>::SetZeroRows( int r1=-1, int r2=-1, int r3=-1, int r4=-1, int r5=-1, int r6=-1 )
^ ~~
outofline.cpp:16:57: error: default arguments cannot be added to an out-of-line definition of a member of a class template
void covar_matrix<realnum>::SetZeroRows( int r1=-1, int r2=-1, int r3=-1, int r4=-1, int r5=-1, int r6=-1 )
^ ~~
outofline.cpp:16:68: error: default arguments cannot be added to an out-of-line definition of a member of a class template
void covar_matrix<realnum>::SetZeroRows( int r1=-1, int r2=-1, int r3=-1, int r4=-1, int r5=-1, int r6=-1 )
^ ~~
outofline.cpp:16:79: error: default arguments cannot be added to an out-of-line definition of a member of a class template
void covar_matrix<realnum>::SetZeroRows( int r1=-1, int r2=-1, int r3=-1, int r4=-1, int r5=-1, int r6=-1 )
^ ~~
outofline.cpp:16:90: error: default arguments cannot be added to an out-of-line definition of a member of a class template
void covar_matrix<realnum>::SetZeroRows( int r1=-1, int r2=-1, int r3=-1, int r4=-1, int r5=-1, int r6=-1 )
^ ~~
outofline.cpp:16:101: error: default arguments cannot be added to an out-of-line definition of a member of a class template
void covar_matrix<realnum>::SetZeroRows( int r1=-1, int r2=-1, int r3=-1, int r4=-1, int r5=-1, int r6=-1 )
^ ~~
6 errors generated.
I assume this isn't a bug in clang. If so, what is the proper solution? Is it this change?
--------------- outofline2.cpp ---------------
template <typename realnum>
class covar_matrix
{
public:
void SetZeroRows(int,int,int,int,int,int); // specifies the order numbers of rows(=columns) for which the covariances should be 0.
private:
};
// defines zero rows. If the first argument is negative, resets all no non-zero.
template <typename realnum>
void covar_matrix<realnum>::SetZeroRows( int r1, int r2, int r3, int r4, int r5, int r6 )
{
int r[6] = {r1,r2,r3,r4,r5,r6};
int i=0;
r1=-1;
r2=-1;
r3=-1;
r4=-1;
r5=-1;
r6=-1;
}
----------------------------------------------
This compiles without complaint in clang. Thanks in advance for any clarifications.
Jack
More information about the cfe-dev
mailing list