1 // { dg-do run } 2 3 // Copyright (C) 2000 Free Software Foundation, Inc. 4 // Contributed by Nathan Sidwell 14 Nov 2000 <nathan@codesourcery.com> 5 6 // Bug 635. We failed to emit initializer code for out-of-class defined 7 // static const members of template instantiations. 8 9 static int inited = 0; 10 setFlag()11static bool setFlag() 12 { 13 inited++; 14 return true; 15 } 16 17 template<typename T> struct X 18 { 19 static const bool cflag; 20 static bool flag; 21 static const bool iflag = true; 22 static const bool jflag = true; 23 }; 24 25 template<typename T> const bool X<T>::cflag (setFlag ()); 26 template<typename T> bool X<T>::flag (setFlag ()); 27 template<typename T> const bool X<T>::iflag; 28 main()29int main () 30 { 31 X<int> a; 32 if (!a.flag) 33 return 1; 34 if (!a.cflag) 35 return 2; 36 if (!a.iflag) 37 return 3; 38 if (!a.jflag) 39 return 5; 40 if (!X<float>::flag) 41 return 5; 42 if (!X<float>::cflag) 43 return 6; 44 if (!X<float>::iflag) 45 return 7; 46 if (!X<float>::jflag) 47 return 8; 48 if (inited != 4) 49 return 9; 50 return 0; 51 } 52 53 // On platforms that do not have weak symbols, these static data 54 // members must be explicitly instantiated. The iflag and jflag data 55 // members should not have to be explicitly instantiated because their 56 // const-ness should allow the compiler to elide references to the 57 // actual variables. 58 template const bool X<int>::cflag; 59 template bool X<int>::flag; 60 template const bool X<float>::cflag; 61 template bool X<float>::flag; 62