1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -ftemplate-depth 16 -fcxx-exceptions -fexceptions %s
3 // DR1330: an exception specification for a function template is only
4 // instantiated when it is needed.
6 template<typename T> void f1(T*) throw(T); // expected-error{{incomplete type 'Incomplete' is not allowed in exception specification}}
7 struct Incomplete; // expected-note{{forward}}
9 void test_f1(Incomplete *incomplete_p, int *int_p) {
11 f1(incomplete_p); // expected-note{{instantiation of exception spec}}
14 template<typename T> struct A {
15 template<typename U> struct B {
16 static void f() noexcept(A<U>().n);
19 constexpr A() : n(true) {}
23 static_assert(noexcept(A<int>::B<char>::f()), "");
25 template<unsigned N> struct S {
26 static void recurse() noexcept(noexcept(S<N+1>::recurse())); // \
27 // expected-error {{no member named 'recurse'}} \
28 // expected-note 9{{instantiation of exception spec}}
30 decltype(S<0>::recurse()) *pVoid1 = 0; // ok, exception spec not needed
31 decltype(&S<0>::recurse) pFn = 0; // ok, exception spec not needed
33 template<> struct S<10> {};
34 void (*pFn2)() noexcept = &S<0>::recurse; // expected-note {{instantiation of exception spec}} expected-error {{not superset}}
37 namespace dr1330_example {
38 template <class T> struct A {
39 void f(...) throw (typename T::X); // expected-error {{'int'}}
49 static int f() noexcept(noexcept(A<T>().f("boo!"))) { return 0; } // \
50 // expected-note {{instantiation of exception spec}}
51 typedef decltype(f<S>()) X;
56 S().f<int>(); // expected-note {{instantiation of exception spec}}
60 namespace core_19754_example {
61 template<typename T> T declval() noexcept;
63 template<typename T, typename = decltype(T(declval<T&&>()))>
64 struct is_movable { static const bool value = true; };
69 void irrelevant(wrap &p) noexcept(is_movable<T>::value);
75 base(const typename T::type1 &);
76 base(const typename T::type2 &);
81 wrap<typename T::base> base;
86 wrap<typename T::base> base;
90 typedef base<types> base;
91 typedef type1<types> type1;
92 typedef type2<types> type2;
95 base<types> val = base<types>();
99 template <typename T> void f1(T) throw(typename T::exception); // expected-note {{candidate}}
100 template <typename T> void f1(T, int = 0) throw(typename T::noitpecxe); // expected-note {{candidate}}
102 template <typename T> void f2(T) noexcept(T::throws); // expected-note {{candidate}}
103 template <typename T> void f2(T, int = 0) noexcept(T::sworht); // expected-note {{candidate}}
106 f1(0); // expected-error {{ambiguous}}
107 f2(0); // expected-error {{ambiguous}}
111 struct Exc1 { char c[4]; };
112 struct Exc2 { double x, y, z; };
114 virtual void f() noexcept; // expected-note {{overridden}}
116 template<typename T> struct Derived : Base {
117 void f() noexcept (sizeof(T) == 4); // expected-error {{is more lax}}
118 void g() noexcept (T::error);
121 Derived<Exc1> d1; // ok
122 Derived<Exc2> d2; // expected-note {{in instantiation of}}
124 // If the vtable for a derived class is used, the exception specification of
125 // any member function which ends up in that vtable is needed, even if it was
126 // declared in a base class.
128 template<bool *B> struct T {
129 virtual void f() noexcept (*B); // expected-error {{constant expression}} expected-note {{read of non-const}}
131 bool b; // expected-note {{here}}
132 struct X : public T<&b> {
135 void X::g() {} // expected-note {{in instantiation of}}