Douglas Gregor | 44eac33 | 2010-07-13 06:02:28 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -O1 -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s |
Rafael Espindola | f3eaf45 | 2010-03-24 22:43:31 +0000 | [diff] [blame] | 2 | |
| 3 | // CHECK-NOT: @_ZTVN5test118stdio_sync_filebufIwEE = constant |
Rafael Espindola | e0f3867 | 2010-03-30 18:07:27 +0000 | [diff] [blame] | 4 | // CHECK-NOT: _ZTVN5test315basic_fstreamXXIcEE |
Rafael Espindola | 9f959db | 2011-01-11 21:10:26 +0000 | [diff] [blame] | 5 | // CHECK: @_ZTVN5test018stdio_sync_filebufIwEE = unnamed_addr constant |
Rafael Espindola | f3eaf45 | 2010-03-24 22:43:31 +0000 | [diff] [blame] | 6 | |
Argyrios Kyrtzidis | 3bd5b6c | 2010-10-13 02:39:41 +0000 | [diff] [blame] | 7 | // CHECK-NOT: _ZTVN5test31SIiEE |
| 8 | // CHECK-NOT: _ZTSN5test31SIiEE |
| 9 | |
Rafael Espindola | 0691a5c | 2011-01-25 19:10:24 +0000 | [diff] [blame^] | 10 | // CHECK: define linkonce_odr void @_ZN5test21CIiEC1Ev(%"class.test2::C"* nocapture %this) unnamed_addr |
Rafael Espindola | f3eaf45 | 2010-03-24 22:43:31 +0000 | [diff] [blame] | 11 | // CHECK: define linkonce_odr void @_ZN5test21CIiE6foobarIdEEvT_( |
| 12 | // CHECK: define available_externally void @_ZN5test21CIiE6zedbarEd( |
| 13 | |
| 14 | namespace test0 { |
| 15 | struct basic_streambuf { |
| 16 | virtual ~basic_streambuf(); |
| 17 | }; |
| 18 | template<typename _CharT > |
| 19 | struct stdio_sync_filebuf : public basic_streambuf { |
| 20 | virtual void xsgetn(); |
| 21 | }; |
| 22 | |
| 23 | // This specialization should cause the vtable to be emitted, even with |
| 24 | // the following extern template declaration. |
| 25 | template<> void stdio_sync_filebuf<wchar_t>::xsgetn() { |
| 26 | } |
| 27 | extern template class stdio_sync_filebuf<wchar_t>; |
| 28 | } |
| 29 | |
| 30 | namespace test1 { |
| 31 | struct basic_streambuf { |
| 32 | virtual ~basic_streambuf(); |
| 33 | }; |
| 34 | template<typename _CharT > |
| 35 | struct stdio_sync_filebuf : public basic_streambuf { |
| 36 | virtual void xsgetn(); |
| 37 | }; |
| 38 | |
| 39 | // Just a declaration should not force the vtable to be emitted. |
| 40 | template<> void stdio_sync_filebuf<wchar_t>::xsgetn(); |
| 41 | } |
| 42 | |
| 43 | namespace test2 { |
| 44 | template<typename T1> |
| 45 | class C { |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 46 | public: |
Rafael Espindola | f3eaf45 | 2010-03-24 22:43:31 +0000 | [diff] [blame] | 47 | virtual ~C(); |
| 48 | void zedbar(double) { |
| 49 | } |
| 50 | template<typename T2> |
| 51 | void foobar(T2 foo) { |
| 52 | } |
| 53 | }; |
| 54 | extern template class C<int>; |
| 55 | void g() { |
| 56 | // The extern template declaration should not prevent us from producing |
| 57 | // the implicit constructor (test at the top). |
| 58 | C<int> a; |
| 59 | |
| 60 | // or foobar(test at the top). |
| 61 | a.foobar(0.0); |
| 62 | |
| 63 | // But it should prevent zebbar |
| 64 | // (test at the top). |
| 65 | a.zedbar(0.0); |
| 66 | } |
| 67 | } |
Rafael Espindola | e0f3867 | 2010-03-30 18:07:27 +0000 | [diff] [blame] | 68 | |
| 69 | namespace test3 { |
| 70 | template<typename T> |
| 71 | class basic_fstreamXX { |
| 72 | virtual void foo(){} |
| 73 | virtual void is_open() const { } |
| 74 | }; |
| 75 | |
| 76 | extern template class basic_fstreamXX<char>; |
| 77 | // This template instantiation should not cause us to produce a vtable. |
| 78 | // (test at the top). |
| 79 | template void basic_fstreamXX<char>::is_open() const; |
| 80 | } |
Argyrios Kyrtzidis | 3bd5b6c | 2010-10-13 02:39:41 +0000 | [diff] [blame] | 81 | |
| 82 | namespace test3 { |
| 83 | template <typename T> |
| 84 | struct S { |
| 85 | virtual void m(); |
| 86 | }; |
| 87 | |
| 88 | template<typename T> |
| 89 | void S<T>::m() { } |
| 90 | |
| 91 | // Should not cause us to produce vtable because template instantiations |
| 92 | // don't have key functions. |
| 93 | template void S<int>::m(); |
| 94 | } |
John McCall | 6102ca1 | 2010-10-16 06:59:13 +0000 | [diff] [blame] | 95 | |
| 96 | namespace test4 { |
| 97 | template <class T> struct A { static void foo(); }; |
| 98 | |
| 99 | class B { |
| 100 | template <class T> friend void A<T>::foo(); |
| 101 | B(); |
| 102 | }; |
| 103 | |
| 104 | template <class T> void A<T>::foo() { |
| 105 | B b; |
| 106 | } |
| 107 | |
| 108 | unsigned test() { |
| 109 | A<int>::foo(); |
| 110 | } |
| 111 | } |
Argyrios Kyrtzidis | bb5e431 | 2010-11-04 03:18:57 +0000 | [diff] [blame] | 112 | |
| 113 | namespace PR8505 { |
| 114 | // Hits an assertion due to bogus instantiation of class B. |
| 115 | template <int i> class A { |
| 116 | class B* g; |
| 117 | }; |
| 118 | class B { |
| 119 | void f () {} |
| 120 | }; |
| 121 | // Should not instantiate class B since it is introduced in namespace scope. |
| 122 | // CHECK-NOT: _ZN6PR85051AILi0EE1B1fEv |
| 123 | template class A<0>; |
| 124 | } |