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