This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13332] New: template static const unsigned does not appear in .o file
- From: "gianni at mariani dot ws" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Dec 2003 08:11:28 -0000
- Subject: [Bug c++/13332] New: template static const unsigned does not appear in .o file
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
This code will compile fine but fail on a linker error.
templ_examp.cpp:41: undefined reference to `Bounds<float, (unsigned)4>::size'
However if "static const unsigned size" is changed from an "unsigned" to an
"int" or "short", it appears to work correctly.
template <typename T, unsigned N>
class Bounds
{
public:
static const unsigned size = N;
T * ptr;
T & operator[] ( unsigned i )
{
if ( i >= size )
{
throw "Array outa bounds";
}
return ptr[ i ];
}
Bounds( T ( & i_ptr)[N] )
: ptr( i_ptr )
{
}
};
template <typename T, unsigned N>
Bounds<T,N> make_bounds( T ( & i_ptr)[N] )
{
return Bounds<T,N>( i_ptr );
}
float array[] = { 1., 2., 3., 4. };
#include <iostream>
int main()
{
std::cout << make_bounds( array )[ 2 ];
std::cout << make_bounds( array ).size;
// std::cout << make_bounds( array )[ 20 ]; // throw exception
}
--
Summary: template static const unsigned does not appear in .o
file
Product: gcc
Version: 3.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gianni at mariani dot ws
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13332