Template compilation error in Sun Studio 12
Posted
by
Jagannath
on Stack Overflow
See other posts from Stack Overflow
or by Jagannath
Published on 2012-07-02T15:11:04Z
Indexed on
2012/07/05
3:16 UTC
Read the original article
Hit count: 240
We are migrating to Sun Studio 12.1 and with the new compiler [ CC: Sun C++ 5.10 SunOS_sparc 2009/06/03 ]. I am getting compilation error while compiling a code that compiled fine with earlier version of Sun Compiler [ CC: Sun WorkShop 6 update 2 C++ 5.3 2001/05/15 ].
This is the compilation error I get.
"Sample.cc": Error: Could not find a match for LoopThrough(int[2]) needed in main(). 1 Error(s) detected. * Error code 1.
CODE:
#include <iostream>
#define PRINT_TRACE(STR) \
std::cout << __FILE__ << ":" << __LINE__ << ":" << STR << "\n";
template<size_t SZ>
void LoopThrough(const int(&Item)[SZ])
{
PRINT_TRACE("Specialized version");
for (size_t index = 0; index < SZ; ++index)
{
std::cout << Item[index] << "\n";
}
}
/*
template<typename Type, size_t SZ>
void LoopThrough(const Type(&Item)[SZ])
{
PRINT_TRACE("Generic version");
}
*/
int main()
{
{
int arr[] = { 1, 2 };
LoopThrough(arr);
}
}
If I uncomment the code with Generic version, the code compiles fine and the generic version is called. I don't see this problem with MSVC 2010 with extensions disabled and the same case with ideone here. The specialized version of the function is called. Now the question is, is this a bug in Sun Compiler ?
If yes, how could we file a bug report ?
© Stack Overflow or respective owner