p16.cpp 948 B

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