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