Hi,

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_of_ones

{

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

>1;

static const unsigned long m_count = static_number_of_ones<T, N, S -

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

};

template <typename T, T N>

struct static_number_of_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_is_power_of_2

{

static const bool m_result = (static_number_of_ones<unsigned 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_is_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_is_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_power_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<16>".

"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_power_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<17>".

"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