template-instantiation.cpp revision 7002f4c03c2d0544f4e8bea8d3a5636519081e35
1// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s 2 3// CHECK-NOT: @_ZTVN5test118stdio_sync_filebufIwEE = constant 4// CHECK-NOT: _ZTVN5test315basic_fstreamXXIcEE 5// CHECK: @_ZTVN5test018stdio_sync_filebufIwEE = constant 6 7// CHECK: define linkonce_odr void @_ZN5test21CIiEC1Ev( 8// CHECK: define linkonce_odr void @_ZN5test21CIiE6foobarIdEEvT_( 9// CHECK: define available_externally void @_ZN5test21CIiE6zedbarEd( 10 11namespace test0 { 12 struct basic_streambuf { 13 virtual ~basic_streambuf(); 14 }; 15 template<typename _CharT > 16 struct stdio_sync_filebuf : public basic_streambuf { 17 virtual void xsgetn(); 18 }; 19 20 // This specialization should cause the vtable to be emitted, even with 21 // the following extern template declaration. 22 template<> void stdio_sync_filebuf<wchar_t>::xsgetn() { 23 } 24 extern template class stdio_sync_filebuf<wchar_t>; 25} 26 27namespace test1 { 28 struct basic_streambuf { 29 virtual ~basic_streambuf(); 30 }; 31 template<typename _CharT > 32 struct stdio_sync_filebuf : public basic_streambuf { 33 virtual void xsgetn(); 34 }; 35 36 // Just a declaration should not force the vtable to be emitted. 37 template<> void stdio_sync_filebuf<wchar_t>::xsgetn(); 38} 39 40namespace test2 { 41 template<typename T1> 42 class C { 43 public: 44 virtual ~C(); 45 void zedbar(double) { 46 } 47 template<typename T2> 48 void foobar(T2 foo) { 49 } 50 }; 51 extern template class C<int>; 52 void g() { 53 // The extern template declaration should not prevent us from producing 54 // the implicit constructor (test at the top). 55 C<int> a; 56 57 // or foobar(test at the top). 58 a.foobar(0.0); 59 60 // But it should prevent zebbar 61 // (test at the top). 62 a.zedbar(0.0); 63 } 64} 65 66namespace test3 { 67 template<typename T> 68 class basic_fstreamXX { 69 virtual void foo(){} 70 virtual void is_open() const { } 71 }; 72 73 extern template class basic_fstreamXX<char>; 74 // This template instantiation should not cause us to produce a vtable. 75 // (test at the top). 76 template void basic_fstreamXX<char>::is_open() const; 77} 78