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

* [Bug c++/13332] template static const unsigned does not appear in .o file
  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 ` pinskia at gcc dot gnu dot org
  2003-12-06  8:50 ` gianni at mariani dot ws
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-06  8:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-06 08:18 -------
>From bug 13259 which this is bug is a dup of:
The standard says that you may inline-initialize the static variable,
but you still need to _define_ it somewhere so that a memory location
is assigned to it.

*** This bug has been marked as a duplicate of 13259 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13332


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

* [Bug c++/13332] template static const unsigned does not appear in .o file
  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
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: gianni at mariani dot ws @ 2003-12-06  8:50 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gianni at mariani dot ws  2003-12-06 08:50 -------

* still need to _define_ *

So what is it if it's not a definition ?

and 

Why don't these problems appear for types other than unsigned ?




-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13332


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

* [Bug c++/13332] template static const unsigned does not appear in .o file
  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
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-06  8:54 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-06 08:54 -------
The reason is that they are optimized out but the optimization is not a bug (but there is another 
bug for not getting an error which already have a different bug).

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13332


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

* [Bug c++/13332] template static const unsigned does not appear in .o file
  2003-12-06  8:11 [Bug c++/13332] New: template static const unsigned does not appear in .o file gianni at mariani dot ws
                   ` (2 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2003-12-06 21:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2003-12-06 21:16 -------
A definition in your case looks like 
  template <ypename T, unsigned int> const unsigned ind Bounds<T,N>::size; 
 
W. 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13332


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

* [Bug c++/13332] template static const unsigned does not appear in .o file
  2003-12-06  8:11 [Bug c++/13332] New: template static const unsigned does not appear in .o file gianni at mariani dot ws
                   ` (3 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-08 17:20 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-08 17:20 -------
*** Bug 13356 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |akim at lrde dot epita dot
                   |                            |fr


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13332


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

* [Bug c++/13332] template static const unsigned does not appear in .o file
  2003-12-06  8:11 [Bug c++/13332] New: template static const unsigned does not appear in .o file gianni at mariani dot ws
                   ` (4 preceding siblings ...)
  2003-12-08 17:20 ` pinskia at gcc dot gnu dot org
@ 2004-01-21 19:20 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-21 19:20 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-21 19:20 -------
*** Bug 13795 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |perry at kundert dot ca


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