Compilation problem on SUN CC compiler with template in 64-bitaddressing model

A

Alex Vinokur

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 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
 
F

Fokko Beekhof

Alex said:
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

Hi,

sorry, but this is off-topic here: your problem is not with C++ itself,
but with a particular product from a particular vendor.
The place to talk about this would be bugs.sun.com or sun's forums, not
here.

Having said that, Sun's CC compiler doesn't compile any of my code
either; my bug reports as well as many others about templates are
acknowledged but no solution has been made available.

I'd advise to try another compiler.

Cheers,
F. Beekhof


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 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top