1c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin10.0.0 -o - %s | FileCheck %s
2c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor
3c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor// PR7050
4c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregortemplate<class T> struct X0 : public T { };
5c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor
6c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregortemplate <class T>
7c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregorstruct X1
8c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor{
9c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor     static T & instance;
10c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor    // include this to provoke instantiation at pre-execution time
11c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor    static void use(T const &) {}
12c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor     static T & get() {
13c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor        static X0<T> t;
14c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor        use(instance);
15c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor        return static_cast<T &>(t);
16c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor    }
17c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor};
18c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor
196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: @_ZN2X1I2X2I1BEE8instanceE = linkonce_odr global %struct.X2* null, align 8
206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECJ: @_ZN2X1I2X2I1AEE8instanceE = linkonce_odr global %struct.X2* null, align 8
21c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregortemplate<class T> T & X1<T>::instance = X1<T>::get();
22c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor
23c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregorclass A { };
24c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregorclass B : public A { };
25c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregor
26c446d1816f46a4b6d2337102dfc001f55fc18211Douglas Gregortemplate<typename T> struct X2 {};
27c446d1816f46a4b6d2337102dfc001f55fc18211Douglas GregorX2< B > bg = X1< X2< B > >::get();
28c446d1816f46a4b6d2337102dfc001f55fc18211Douglas GregorX2< A > ag = X1< X2< A > >::get();
29