// RUN: %clang_cc1 -fsyntax-only -verify -triple %itanium_abi_triple -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. // Note: the test is Itanium-specific because it depends on key functions in the // PR12763 namespace. 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}} }; template<> struct S<10> {}; void (*pFn2)() noexcept = &S<0>::recurse; // expected-note {{instantiation of exception spec}} expected-error {{not superset}} namespace dr1330_example { template struct A { void f(...) throw (typename T::X); void f(int); }; int main() { A().f(42); } struct S { template static void f() throw(typename T::X); typedef decltype(f()) X; // expected-error {{exception specification is not available}} }; struct T { template static void f() throw(T**); typedef decltype(f()) X; // expected-error {{exception specification is not available}} }; template struct U { void f() noexcept(T::error); void (g)() noexcept(T::error); }; U uint; // ok } 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}} // If the vtable for a derived class is used, the exception specification of // any member function which ends up in that vtable is needed, even if it was // declared in a base class. namespace PR12763 { template struct T { virtual void f() noexcept (*B); // expected-error {{constant expression}} expected-note {{read of non-const}} }; bool b; // expected-note {{here}} struct X : public T<&b> { virtual void g(); }; void X::g() {} // expected-note {{in instantiation of}} } namespace Variadic { template void check() { static_assert(B, ""); } template void check() { static_assert(B, ""); check(); } template void consume(T...); template void f(void (*...p)() throw (T)) { void (*q[])() = { p... }; consume((p(),0)...); } template void g(void (*...p)() noexcept (B)) { consume((p(),0)...); check(); } template void i() { consume([]() throw(T) {} ...); consume([]() noexcept(sizeof(T) == 4) {} ...); } template void j() { consume([](void (*p)() noexcept(B)) { void (*q)() noexcept = p; // expected-error {{not superset of source}} } ...); } void z() { f(nullptr, nullptr, nullptr); g(nullptr, nullptr, nullptr); i(); j(); j(); // expected-note {{in instantiation of}} } } namespace NondefDecls { template void f1() { int g1(int) noexcept(T::error); // expected-error{{type 'int' cannot be used prior to '::' because it has no members}} } template void f1(); // expected-note{{in instantiation of function template specialization 'NondefDecls::f1' requested here}} }