I have compilation problem on SUN CC compiler with template while

using option -m64 (64-bit addressing model).

No problem while using option -m32 (32-bit addressing model)

$ CC -V

CC: Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25

Here is some C++ program

############# foo5.cpp #############

//-----

template <typename T, T N, unsigned long S = sizeof(T) * 8>

struct static_number_o f_ones

{

static const T m_value = static_number_o f_ones<T, N, S - 1>::m_value

static const unsigned long m_count = static_number_o f_ones<T, N, S ->1;

1>::m_count + (static_number_ of_ones<T, N, S - 1>::m_value & 0x1);

};

template <typename T, T N>

struct static_number_o f_ones<T, N, 0>

{

static const T m_value = N;

static const unsigned long m_count = 0;

};

//-----

template <typename T, T N>

struct static_is_power _of_2

{

static const bool m_result = (static_number_ of_ones<T,N>::m _count ==

1);

};

template <unsigned long N>

struct static_number_i s_power_of_2

{

static const bool m_result = (static_number_ of_ones<unsigne d long,

N>::m_count == 1);

};

int main(int argc)

{

int ret = 0;

if (argc 1)

{

ret += static_is_power _of_2<unsigned short, 16>::m_result;

ret += static_is_power _of_2<unsigned int, 16>::m_result;

ret += static_is_power _of_2<unsigned long, 16>::m_result;

ret += static_number_i s_power_of_2<16 >::m_result;

}

else

{

ret += static_is_power _of_2<unsigned short, 17>::m_result;

ret += static_is_power _of_2<unsigned int, 17>::m_result;

ret += static_is_power _of_2<unsigned long, 17>::m_result;

ret += static_number_i s_power_of_2<17 >::m_result;

}

return ret;

}

############### ############### ####

Compiation:

@ CC -m32 foo5.cpp

// No problem

@ CC -m64 foo5.cpp

"foo5.cpp", line 20: Error: An integer constant expression is required

here.

"foo5.cpp", line 36: Where: While specializing

"static_is_powe r_of_2<unsigned long, 16>".

"foo5.cpp", line 36: Where: Specialized in non-template code.

"foo5.cpp", line 26: Error: An integer constant expression is required

here.

"foo5.cpp", line 37: Where: While specializing

"static_number_ is_power_of_2<1 6>".

"foo5.cpp", line 37: Where: Specialized in non-template code.

"foo5.cpp", line 20: Error: An integer constant expression is required

here.

"foo5.cpp", line 43: Where: While specializing

"static_is_powe r_of_2<unsigned long, 17>".

"foo5.cpp", line 43: Where: Specialized in non-template code.

"foo5.cpp", line 26: Error: An integer constant expression is required

here.

"foo5.cpp", line 44: Where: While specializing

"static_number_ is_power_of_2<1 7>".

"foo5.cpp", line 44: Where: Specialized in non-template code.

4 Error(s) detected.

=============== ==========

It seems that in 64-bit addressing model on Sun

unsigned long is not a primitive type (?)

static_is_power _of_2<unsigned int, 16>::m_result; // No compilation

problem

static_is_power _of_2<unsigned long, 16>::m_result; // Compilation

problem

P.S. No problem with that program on HP-UX in 64-bit addressing model

Compiler aCC: HP C/aC++ B3910B A.06.15 [May 16 2007]

Thanks,

Alex Vinokur