diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CXX/except/except.spec/p1.cpp | 4 | ||||
-rw-r--r-- | test/CodeGenCXX/cxx11-exception-spec.cpp | 18 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-declref.cpp | 10 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-exception-spec-cxx11.cpp | 107 |
4 files changed, 137 insertions, 2 deletions
diff --git a/test/CXX/except/except.spec/p1.cpp b/test/CXX/except/except.spec/p1.cpp index c68ec56a24..e184ec4ffa 100644 --- a/test/CXX/except/except.spec/p1.cpp +++ b/test/CXX/except/except.spec/p1.cpp @@ -65,7 +65,7 @@ namespace noexcept_unevaluated { } template<typename T> - void g(T x) noexcept((sizeof(T) == sizeof(int)) || f(x)) { } + void g(T x) noexcept((sizeof(T) == sizeof(int)) || noexcept(f(x))) { } void h() { g(1); @@ -77,5 +77,5 @@ namespace PR11084 { static int f() noexcept(1/X) { return 10; } // expected-error{{argument to noexcept specifier must be a constant expression}} expected-note{{division by zero}} }; - void g() { A<0>::f(); } // expected-note{{in instantiation of template class 'PR11084::A<0>' requested here}} + void g() { A<0>::f(); } // expected-note{{in instantiation of exception specification for 'f' requested here}} } diff --git a/test/CodeGenCXX/cxx11-exception-spec.cpp b/test/CodeGenCXX/cxx11-exception-spec.cpp new file mode 100644 index 0000000000..461af78eae --- /dev/null +++ b/test/CodeGenCXX/cxx11-exception-spec.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++11 -verify -emit-llvm %s -o - | FileCheck %s + +template<typename T> void f() noexcept(sizeof(T) == 4); + +void g() { + // CHECK: declare void @_Z1fIiEvv() nounwind + f<int>(); + // CHECK: declare void @_Z1fIA2_iEvv() + f<int[2]>(); + // CHECK: declare void @_Z1fIfEvv() nounwind + void (*f1)() = &f<float>; + // CHECK: declare void @_Z1fIdEvv() + void (*f2)() = &f<double>; + // CHECK: declare void @_Z1fIA4_cEvv() nounwind + (void)&f<char[4]>; + // CHECK: declare void @_Z1fIcEvv() + (void)&f<char>; +} diff --git a/test/SemaTemplate/instantiate-declref.cpp b/test/SemaTemplate/instantiate-declref.cpp index ced56dfc6a..7d4a2ff6a3 100644 --- a/test/SemaTemplate/instantiate-declref.cpp +++ b/test/SemaTemplate/instantiate-declref.cpp @@ -105,3 +105,13 @@ namespace test1 { } template void f(int const &); // expected-note {{requested here}} } + +namespace test2 { + template<typename T> void f() { + T::error; // expected-error {{no member}} + } + void g() { + // This counts as an odr-use, so should trigger the instantiation of f<int>. + (void)&f<int>; // expected-note {{here}} + } +} diff --git a/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp b/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp new file mode 100644 index 0000000000..763b9ed41b --- /dev/null +++ b/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp @@ -0,0 +1,107 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -ftemplate-depth 16 %s + +// DR1330: an exception specification for a function template is only +// instantiated when it is needed. + +template<typename T> void f1(T*) throw(T); // expected-error{{incomplete type 'Incomplete' is not allowed in exception specification}} +struct Incomplete; // expected-note{{forward}} + +void test_f1(Incomplete *incomplete_p, int *int_p) { + f1(int_p); + f1(incomplete_p); // expected-note{{instantiation of exception spec}} +} + +template<typename T> struct A { + template<typename U> struct B { + static void f() noexcept(A<U>().n); + }; + + constexpr A() : n(true) {} + bool n; +}; + +static_assert(noexcept(A<int>::B<char>::f()), ""); + +template<unsigned N> struct S { + static void recurse() noexcept(noexcept(S<N+1>::recurse())); // \ + // expected-error {{no member named 'recurse'}} \ + // expected-note 9{{instantiation of exception spec}} +}; +decltype(S<0>::recurse()) *pVoid1 = 0; // ok, exception spec not needed +decltype(&S<0>::recurse) pFn = 0; // ok, exception spec not needed + +template<> struct S<10> {}; +void (*pFn2)() noexcept = &S<0>::recurse; // expected-note {{instantiation of exception spec}} + + +template<typename T> T go(T a) noexcept(noexcept(go(a))); // \ +// expected-error 16{{call to function 'go' that is neither visible}} \ +// expected-note 16{{'go' should be declared prior to the call site}} \ +// expected-error {{recursive template instantiation exceeded maximum depth of 16}} \ +// expected-error {{use of undeclared identifier 'go'}} \ + +void f() { + int k = go(0); // \ + // expected-note {{in instantiation of exception specification for 'go<int>' requested here}} +} + + +namespace dr1330_example { + template <class T> struct A { + void f(...) throw (typename T::X); // expected-error {{'int'}} + void f(int); + }; + + int main() { + A<int>().f(42); + } + + int test2() { + struct S { + template<typename T> + static int f() noexcept(noexcept(A<T>().f("boo!"))) { return 0; } // \ + // expected-note {{instantiation of exception spec}} + typedef decltype(f<S>()) X; + }; + S().f<S>(); // ok + S().f<int>(); // expected-note {{instantiation of exception spec}} + } +} + +namespace core_19754_example { + template<typename T> T declval() noexcept; + + template<typename T, typename = decltype(T(declval<T&&>()))> + struct is_movable { static const bool value = true; }; + + template<typename T> + struct wrap { + T val; + void irrelevant(wrap &p) noexcept(is_movable<T>::value); + }; + + template<typename T> + struct base { + base() {} + base(const typename T::type1 &); + base(const typename T::type2 &); + }; + + template<typename T> + struct type1 { + wrap<typename T::base> base; + }; + + template<typename T> + struct type2 { + wrap<typename T::base> base; + }; + + struct types { + typedef base<types> base; + typedef type1<types> type1; + typedef type2<types> type2; + }; + + base<types> val = base<types>(); +} |