blob: 635e1d2099b80d6ea5e39989cf3546d25967adb8 [file] [log] [blame]
Douglas Gregor44eac332010-07-13 06:02:28 +00001// RUN: %clang_cc1 %s -O1 -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
Rafael Espindolaf3eaf452010-03-24 22:43:31 +00002
3// CHECK-NOT: @_ZTVN5test118stdio_sync_filebufIwEE = constant
Rafael Espindolae0f38672010-03-30 18:07:27 +00004// CHECK-NOT: _ZTVN5test315basic_fstreamXXIcEE
Rafael Espindola9f959db2011-01-11 21:10:26 +00005// CHECK: @_ZTVN5test018stdio_sync_filebufIwEE = unnamed_addr constant
Rafael Espindolaf3eaf452010-03-24 22:43:31 +00006
Argyrios Kyrtzidis3bd5b6c2010-10-13 02:39:41 +00007// CHECK-NOT: _ZTVN5test31SIiEE
8// CHECK-NOT: _ZTSN5test31SIiEE
9
Rafael Espindola0691a5c2011-01-25 19:10:24 +000010// CHECK: define linkonce_odr void @_ZN5test21CIiEC1Ev(%"class.test2::C"* nocapture %this) unnamed_addr
Rafael Espindolaf3eaf452010-03-24 22:43:31 +000011// CHECK: define linkonce_odr void @_ZN5test21CIiE6foobarIdEEvT_(
12// CHECK: define available_externally void @_ZN5test21CIiE6zedbarEd(
13
14namespace 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
30namespace 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
43namespace test2 {
44 template<typename T1>
45 class C {
John McCall7002f4c2010-04-09 19:03:51 +000046 public:
Rafael Espindolaf3eaf452010-03-24 22:43:31 +000047 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 Espindolae0f38672010-03-30 18:07:27 +000068
69namespace 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 Kyrtzidis3bd5b6c2010-10-13 02:39:41 +000081
82namespace 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 McCall6102ca12010-10-16 06:59:13 +000095
96namespace 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 Kyrtzidisbb5e4312010-11-04 03:18:57 +0000112
113namespace PR8505 {
114// Hits an assertion due to bogus instantiation of class B.
115template <int i> class A {
116 class B* g;
117};
118class B {
119 void f () {}
120};
121// Should not instantiate class B since it is introduced in namespace scope.
122// CHECK-NOT: _ZN6PR85051AILi0EE1B1fEv
123template class A<0>;
124}