From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- .../instantiate-exception-spec-cxx11.cpp | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp (limited to 'clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp') diff --git a/clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp b/clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp new file mode 100644 index 0000000..8a6f9ef --- /dev/null +++ b/clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp @@ -0,0 +1,133 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -ftemplate-depth 16 -fcxx-exceptions -fexceptions %s + +// DR1330: an exception specification for a function template is only +// instantiated when it is needed. + +template 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 struct A { + template struct B { + static void f() noexcept(A().n); + }; + + constexpr A() : n(true) {} + bool n; +}; + +static_assert(noexcept(A::B::f()), ""); + +template struct S { + static void recurse() noexcept(noexcept(S::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}} expected-error {{not superset}} + + +template 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' requested here}} +} + + +namespace dr1330_example { + template struct A { + void f(...) throw (typename T::X); // expected-error {{'int'}} + void f(int); + }; + + int main() { + A().f(42); + } + + int test2() { + struct S { + template + static int f() noexcept(noexcept(A().f("boo!"))) { return 0; } // \ + // expected-note {{instantiation of exception spec}} + typedef decltype(f()) X; + }; + S().f(); // ok + S().f(); // expected-note {{instantiation of exception spec}} + } +} + +namespace core_19754_example { + template T declval() noexcept; + + template()))> + struct is_movable { static const bool value = true; }; + + template + struct wrap { + T val; + void irrelevant(wrap &p) noexcept(is_movable::value); + }; + + template + struct base { + base() {} + base(const typename T::type1 &); + base(const typename T::type2 &); + }; + + template + struct type1 { + wrap base; + }; + + template + struct type2 { + wrap base; + }; + + struct types { + typedef base base; + typedef type1 type1; + typedef type2 type2; + }; + + base val = base(); +} + +namespace pr9485 { + template void f1(T) throw(typename T::exception); // expected-note {{candidate}} + template void f1(T, int = 0) throw(typename T::noitpecxe); // expected-note {{candidate}} + + template void f2(T) noexcept(T::throws); // expected-note {{candidate}} + template void f2(T, int = 0) noexcept(T::sworht); // expected-note {{candidate}} + + void test() { + f1(0); // expected-error {{ambiguous}} + f2(0); // expected-error {{ambiguous}} + } +} + +struct Exc1 { char c[4]; }; +struct Exc2 { double x, y, z; }; +struct Base { + virtual void f() noexcept; // expected-note {{overridden}} +}; +template struct Derived : Base { + void f() noexcept (sizeof(T) == 4); // expected-error {{is more lax}} + void g() noexcept (T::error); +}; + +Derived d1; // ok +Derived d2; // expected-note {{in instantiation of}} -- cgit v1.2.3