2014-01-15 03:35:09 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -triple %itanium_abi_triple -std=c++11 -ftemplate-depth 16 -fcxx-exceptions -fexceptions %s
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
|
|
|
|
// DR1330: an exception specification for a function template is only
|
|
|
|
// instantiated when it is needed.
|
|
|
|
|
2014-01-14 03:48:13 +08:00
|
|
|
// Note: the test is Itanium-specific because it depends on key functions in the
|
|
|
|
// PR12763 namespace.
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
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> {};
|
2012-04-19 08:08:28 +08:00
|
|
|
void (*pFn2)() noexcept = &S<0>::recurse; // expected-note {{instantiation of exception spec}} expected-error {{not superset}}
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-10-22 12:14:18 +08:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
int test2() {
|
|
|
|
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>();
|
|
|
|
}
|
2012-04-18 06:30:01 +08:00
|
|
|
|
|
|
|
namespace pr9485 {
|
|
|
|
template <typename T> void f1(T) throw(typename T::exception); // expected-note {{candidate}}
|
|
|
|
template <typename T> void f1(T, int = 0) throw(typename T::noitpecxe); // expected-note {{candidate}}
|
|
|
|
|
|
|
|
template <typename T> void f2(T) noexcept(T::throws); // expected-note {{candidate}}
|
|
|
|
template <typename T> void f2(T, int = 0) noexcept(T::sworht); // expected-note {{candidate}}
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
f1(0); // expected-error {{ambiguous}}
|
|
|
|
f2(0); // expected-error {{ambiguous}}
|
|
|
|
}
|
|
|
|
}
|
2012-04-19 08:08:28 +08:00
|
|
|
|
|
|
|
struct Exc1 { char c[4]; };
|
|
|
|
struct Exc2 { double x, y, z; };
|
|
|
|
struct Base {
|
|
|
|
virtual void f() noexcept; // expected-note {{overridden}}
|
|
|
|
};
|
|
|
|
template<typename T> struct Derived : Base {
|
|
|
|
void f() noexcept (sizeof(T) == 4); // expected-error {{is more lax}}
|
|
|
|
void g() noexcept (T::error);
|
|
|
|
};
|
|
|
|
|
|
|
|
Derived<Exc1> d1; // ok
|
|
|
|
Derived<Exc2> d2; // expected-note {{in instantiation of}}
|
2012-07-07 14:59:51 +08:00
|
|
|
|
|
|
|
// 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<bool *B> 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}}
|
|
|
|
}
|