xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/static-init-3.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin10.0.0 -o - %s | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc // PR7050
4f4a2713aSLionel Sambuc template<class T> struct X0 : public T { };
5f4a2713aSLionel Sambuc 
6f4a2713aSLionel Sambuc template <class T>
7f4a2713aSLionel Sambuc struct X1
8f4a2713aSLionel Sambuc {
9f4a2713aSLionel Sambuc      static T & instance;
10f4a2713aSLionel Sambuc     // include this to provoke instantiation at pre-execution time
useX111f4a2713aSLionel Sambuc     static void use(T const &) {}
getX112f4a2713aSLionel Sambuc      static T & get() {
13f4a2713aSLionel Sambuc         static X0<T> t;
14f4a2713aSLionel Sambuc         use(instance);
15f4a2713aSLionel Sambuc         return static_cast<T &>(t);
16f4a2713aSLionel Sambuc     }
17f4a2713aSLionel Sambuc };
18f4a2713aSLionel Sambuc 
19*0a6a1f1dSLionel Sambuc // CHECK: @_ZN2X1I2X2I1BEE8instanceE = linkonce_odr global %struct.X2* null, align 8
20*0a6a1f1dSLionel Sambuc // CHECJ: @_ZN2X1I2X2I1AEE8instanceE = linkonce_odr global %struct.X2* null, align 8
21f4a2713aSLionel Sambuc template<class T> T & X1<T>::instance = X1<T>::get();
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc class A { };
24f4a2713aSLionel Sambuc class B : public A { };
25f4a2713aSLionel Sambuc 
26f4a2713aSLionel Sambuc template<typename T> struct X2 {};
27f4a2713aSLionel Sambuc X2< B > bg = X1< X2< B > >::get();
28f4a2713aSLionel Sambuc X2< A > ag = X1< X2< A > >::get();
29