Richard Smith 2e32155b58 Instantiate exception specifications when instantiating function types (other
than the type of a function declaration). We previously didn't instantiate
these at all! This also covers the pathological case where the only mention of
a parameter pack is within the exception specification; this gives us a second
way (other than alias templates) to reach the horrible state where a type
contains an unexpanded pack, but its canonical type does not.


This is a re-commit of r219977:

r219977 was reverted in r220038 because it hit a wrong-code bug in GCC 4.7.2.
(That's gcc.gnu.org/PR56135, and affects any implicit lambda-capture of
'this' within a template.)


r219977 was a re-commit of r217995, r218011, and r218053:

r217995 was reverted in r218058 because it hit a rejects-valid bug in MSVC.
(Incorrect overload resolution in the presence of using-declarations.)
It was re-committed in r219977 with a workaround for the MSVC rejects-valid.

r218011 was a workaround for an MSVC parser bug. (Incorrect desugaring of
unbraced range-based for loop).

llvm-svn: 221750
2014-11-12 02:00:47 +00:00

89 lines
2.0 KiB
C++

// RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
// Simple parser tests, dynamic specification.
namespace dyn {
struct X { };
struct Y { };
void f() throw() { }
void g(int) throw(X) { }
void h() throw(X, Y) { }
class Class {
void foo() throw (X, Y) { }
};
void (*fptr)() throw();
}
// Simple parser tests, noexcept specification.
namespace noex {
void f1() noexcept { }
void f2() noexcept (true) { }
void f3() noexcept (false) { }
void f4() noexcept (1 < 2) { }
class CA1 {
void foo() noexcept { }
void bar() noexcept (true) { }
};
void (*fptr1)() noexcept;
void (*fptr2)() noexcept (true);
}
namespace mix {
void f() throw(int) noexcept { } // expected-error {{cannot have both}}
void g() noexcept throw(int) { } // expected-error {{cannot have both}}
}
// Sema tests, noexcept specification
namespace noex {
struct A {};
void g1() noexcept(A()); // expected-error {{not contextually convertible}}
void g2(bool b) noexcept(b); // expected-error {{argument to noexcept specifier must be a constant expression}} expected-note {{read of non-const variable 'b'}} expected-note {{here}}
}
namespace noexcept_unevaluated {
template<typename T> bool f(T) {
T* x = 1;
}
template<typename T>
void g(T x) noexcept((sizeof(T) == sizeof(int)) || noexcept(f(x))) { }
void h() {
g(1);
}
}
namespace PR11084 {
template<int X> struct A {
static int f() noexcept(1/X) { return 10; } // expected-error{{argument to noexcept specifier must be a constant expression}} expected-note{{division by zero}}
};
template<int X> void f() {
int (*p)() noexcept(1/X); // 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 exception specification for 'f'}}
f<0>(); // expected-note{{in instantiation of function template specialization}}
}
}