template static const initialization with return value
Stefan Schwarzer
sts@ica1.uni-stuttgart.de
Tue Apr 10 08:31:00 GMT 2001
The following code returns 0 to the invoking
environment. I (and KCC and cxx and pgCC) think that
it should return 5, if the initialization is actually
performed at some point. For non-template struct A, the initialization
works fine and the program returns 5 as expected.
I see this behavior in 2.95.1 upward and on Linux and Tru64
platforms (no others tried):
---------------------------------------------------------------------------------------
17:12 castor_sts:~/bugs> g++ -v
Reading specs from /opt/gcc-2.95.3/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/specs
gcc version 2.95.3 20010315 (release)
17:12 castor_sts:~/bugs> uname -a
Linux castor.ica1.uni-stuttgart.de 2.2.13 #2 Sat Dec 18 16:00:25 CET 1999 i686 unknown
17:12 castor_sts:~/bugs> uname
Linux
17:12 castor_sts:~/bugs> g++ -Wall static.cc
17:13 castor_sts:~/bugs> a.out
17:13 castor_sts:~/bugs> echo $status
0
----------------------------------------------------------------------------------------
template <class T>
struct A {
static int init() { return 5; }
static const int our_int;
};
template <class T>
const int A<T>::our_int = A<T>::init();
int main(){
return A<double>::our_int;
}
--
Stefan Schwarzer office: +49-(0)711-685-7606 fax: x-3658
Uni Stuttgart, ICA 1 (?-
Pfaffenwaldring 27 //\ sts@ica1.uni-stuttgart.de
70569 Stuttgart, Germany -V_/---- http://www.ica1.uni-stuttgart.de/~sts
More information about the Gcc-bugs
mailing list