[Bug c++/13332] New: template static const unsigned does not appear in .o file

gianni at mariani dot ws gcc-bugzilla@gcc.gnu.org
Sat Dec 6 08:11:00 GMT 2003


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



More information about the Gcc-bugs mailing list