public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/13332] New: template static const unsigned does not appear in .o file
@ 2003-12-06  8:11 gianni at mariani dot ws
  2003-12-06  8:18 ` [Bug c++/13332] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gianni at mariani dot ws @ 2003-12-06  8:11 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-01-21 19:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-06  8:11 [Bug c++/13332] New: template static const unsigned does not appear in .o file gianni at mariani dot ws
2003-12-06  8:18 ` [Bug c++/13332] " pinskia at gcc dot gnu dot org
2003-12-06  8:50 ` gianni at mariani dot ws
2003-12-06  8:54 ` pinskia at gcc dot gnu dot org
2003-12-06 21:16 ` bangerth at dealii dot org
2003-12-08 17:20 ` pinskia at gcc dot gnu dot org
2004-01-21 19:20 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).