This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[Fwd: Templates with more than one static variable]


This looks like a bug in egcs.  It also has problems if the template static
variable is asigned from a function evalutation like:

int problems<T>::s_i = f(10);

The problem is in egcs 1.0.3

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.90.29/specs
gcc version egcs-2.90.29 980515 (egcs-1.0.3 release)

thanks,

dean


  
Dean Foster wrote:
> 
> I was wondering if the following is a error in my thinking or a bug in egcs.
> Basically what happens is that if you have all the following:
> 
>      (1) two static variables
>      (2) one variable depends on the other for its value
>      (3) you explicitely instantiate the template
> 
> then it claims the variables are multiply defined.  So the following code
> doesn't run:
> 
> #include <iostream.h>
> 
> template<class T>
> class problems
> {
> public:
>   static int s_i;
>   static int s_j;
> };
> 
> template<class T>
> int problems<T>::s_i = 7;
> 
> template<class T>
> int problems<T>::s_j = 2*s_i;  // replacing this with 14 works
> 
> template class problems<int>;
> 
> main()
> {
>   cout << problems<int>::s_i << endl;
>   cout << problems<int>::s_j << endl;
> };
> 
> 
> thanks,
> 
> dean
> 
> (Dean Foster, Dept of Statistics, Wharton, U. of Penn)
> 
>       [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
>       [ about comp.lang.c++.moderated. First time posters: do this! ]


I was wondering if the following is a error in my thinking or a bug in egcs. 
Basically what happens is that if you have all the following:

     (1) two static variables
     (2) one variable depends on the other for its value
     (3) you explicitely instantiate the template

then it claims the variables are multiply defined.  So the following code
doesn't run:

#include <iostream.h>

template<class T>
class problems
{
public:
  static int s_i;
  static int s_j;
};

template<class T>
int problems<T>::s_i = 7;

template<class T>
int problems<T>::s_j = 2*s_i;  // replacing this with 14 works 

template class problems<int>;

main()
{
  cout << problems<int>::s_i << endl;
  cout << problems<int>::s_j << endl;
};

            
thanks,

dean

(Dean Foster, Dept of Statistics, Wharton, U. of Penn)

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]