diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CXX/temp/temp.spec/temp.explicit/p3.cpp | 27 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/explicit-instantiation.cpp | 31 |
2 files changed, 57 insertions, 1 deletions
diff --git a/clang/test/CXX/temp/temp.spec/temp.explicit/p3.cpp b/clang/test/CXX/temp/temp.spec/temp.explicit/p3.cpp index e9758bcdec2..48c42c399a4 100644 --- a/clang/test/CXX/temp/temp.spec/temp.explicit/p3.cpp +++ b/clang/test/CXX/temp/temp.spec/temp.explicit/p3.cpp @@ -2,8 +2,9 @@ // A declaration of a function template shall be in scope at the point of the // explicit instantiation of the function template. -template<typename T> void f0(T) { } +template<typename T> void f0(T); template void f0(int); // okay +template<typename T> void f0(T) { } // A definition of the class or class template containing a member function // template shall be in scope at the point of the explicit instantiation of @@ -47,3 +48,27 @@ template X2<int>::X2(); // expected-error{{not an instantiation}} template X2<int>::X2(const X2&); // expected-error{{not an instantiation}} template X2<int>::~X2(); // expected-error{{not an instantiation}} template X2<int> &X2<int>::operator=(const X2<int>&); // expected-error{{not an instantiation}} + + +// A definition of a class template is sufficient to explicitly +// instantiate a member of the class template which itself is not yet defined. +namespace PR7979 { + template <typename T> struct S { + void f(); + static void g(); + static int i; + struct S2 { + void h(); + }; + }; + + template void S<int>::f(); + template void S<int>::g(); + template int S<int>::i; + template void S<int>::S2::h(); + + template <typename T> void S<T>::f() {} + template <typename T> void S<T>::g() {} + template <typename T> int S<T>::i; + template <typename T> void S<T>::S2::h() {} +} diff --git a/clang/test/CodeGenCXX/explicit-instantiation.cpp b/clang/test/CodeGenCXX/explicit-instantiation.cpp index 24d1a673922..b82958568a8 100644 --- a/clang/test/CodeGenCXX/explicit-instantiation.cpp +++ b/clang/test/CodeGenCXX/explicit-instantiation.cpp @@ -1,5 +1,8 @@ // RUN: %clang_cc1 -emit-llvm -triple i686-pc-linux-gnu -o - %s | FileCheck %s +// This check logically is attached to 'template int S<int>::i;' below. +// CHECK: @_ZN1SIiE1iE = weak global i32 + template<typename T, typename U, typename Result> struct plus { Result operator()(const T& t, const U& u) const; @@ -12,3 +15,31 @@ Result plus<T, U, Result>::operator()(const T& t, const U& u) const { // CHECK: define weak_odr i32 @_ZNK4plusIillEclERKiRKl template struct plus<int, long, long>; + +// Check that we emit definitions from explicit instantiations even when they +// occur prior to the definition itself. +template <typename T> struct S { + void f(); + static void g(); + static int i; + struct S2 { + void h(); + }; +}; + +// CHECK: define weak_odr void @_ZN1SIiE1fEv +template void S<int>::f(); + +// CHECK: define weak_odr void @_ZN1SIiE1gEv +template void S<int>::g(); + +// See the check line at the top of the file. +template int S<int>::i; + +// CHECK: define weak_odr void @_ZN1SIiE2S21hEv +template void S<int>::S2::h(); + +template <typename T> void S<T>::f() {} +template <typename T> void S<T>::g() {} +template <typename T> int S<T>::i; +template <typename T> void S<T>::S2::h() {} |