2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.pt / instantiate12.C
blobef5572f9de2e5c79c1a94b86036bcbfd50ea6837
1 // { dg-do run  }
3 // Copyright (C) 2000 Free Software Foundation, Inc.
4 // Contributed by Nathan Sidwell 14 Nov 2000 <nathan@codesourcery.com>
6 // Bug 635. We failed to emit initializer code for out-of-class defined
7 // static const members of template instantiations.
9 static int inited = 0;
11 static bool setFlag()
13   inited++;
14   return true;
17 template<typename T> struct X
19   static const bool cflag;
20   static bool flag;
21   static const bool iflag = true;
22   static const bool jflag = true;
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;
29 int main ()
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;
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 const bool X<int>::flag;
60 template const bool X<float>::cflag;
61 template const bool X<float>::flag;