xref: /minix3/external/bsd/llvm/dist/clang/test/CXX/except/except.handle/p16.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // The object declared in an exception-declaration or, if the
4*f4a2713aSLionel Sambuc // exception-declaration does not specify a name, a temporary (12.2)
5*f4a2713aSLionel Sambuc // is copy-initialized (8.5) from the exception object.
6*f4a2713aSLionel Sambuc //
7*f4a2713aSLionel Sambuc template<typename T>
8*f4a2713aSLionel Sambuc class X {
9*f4a2713aSLionel Sambuc   T* ptr;
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc public:
X(const X<T> &)12*f4a2713aSLionel Sambuc   X(const X<T> &) {
13*f4a2713aSLionel Sambuc     int *ip = 0;
14*f4a2713aSLionel Sambuc     ptr = ip; // expected-error{{assigning to 'float *' from incompatible type 'int *'}}
15*f4a2713aSLionel Sambuc   }
16*f4a2713aSLionel Sambuc 
~X()17*f4a2713aSLionel Sambuc   ~X() {
18*f4a2713aSLionel Sambuc     float *fp = 0;
19*f4a2713aSLionel Sambuc     ptr = fp; // expected-error{{assigning to 'int *' from incompatible type 'float *'}}
20*f4a2713aSLionel Sambuc   }
21*f4a2713aSLionel Sambuc };
22*f4a2713aSLionel Sambuc 
f()23*f4a2713aSLionel Sambuc void f() {
24*f4a2713aSLionel Sambuc   try {
25*f4a2713aSLionel Sambuc   } catch (X<float>) { // expected-note{{instantiation}}
26*f4a2713aSLionel Sambuc     // copy constructor
27*f4a2713aSLionel Sambuc   } catch (X<int> xi) { // expected-note{{instantiation}}
28*f4a2713aSLionel Sambuc     // destructor
29*f4a2713aSLionel Sambuc   }
30*f4a2713aSLionel Sambuc }
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc struct Abstract {
33*f4a2713aSLionel Sambuc   virtual void f() = 0; // expected-note{{pure virtual}}
34*f4a2713aSLionel Sambuc };
35*f4a2713aSLionel Sambuc 
g()36*f4a2713aSLionel Sambuc void g() {
37*f4a2713aSLionel Sambuc   try {
38*f4a2713aSLionel Sambuc   } catch (Abstract) { // expected-error{{variable type 'Abstract' is an abstract class}}
39*f4a2713aSLionel Sambuc   }
40*f4a2713aSLionel Sambuc }
41