p5-pointers.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
  2. // Assignment of function pointers.
  3. struct A
  4. {
  5. };
  6. struct B1 : A
  7. {
  8. };
  9. struct B2 : A
  10. {
  11. };
  12. struct D : B1, B2
  13. {
  14. };
  15. struct P : private A
  16. {
  17. };
  18. // Some functions to play with below.
  19. void s1() throw();
  20. void s2() throw(int);
  21. void s3() throw(A);
  22. void s4() throw(B1);
  23. void s5() throw(D);
  24. void s6();
  25. void s7() throw(int, float);
  26. void (*s8())() throw(B1); // s8 returns a pointer to function with spec
  27. void s9(void (*)() throw(B1)); // s9 takes pointer to function with spec
  28. void s10() noexcept;
  29. void s11() noexcept(true);
  30. void s12() noexcept(false);
  31. void fnptrs()
  32. {
  33. // Assignment and initialization of function pointers.
  34. void (*t1)() throw() = &s1; // valid
  35. t1 = &s2; // expected-error {{not superset}} expected-error {{incompatible type}}
  36. t1 = &s3; // expected-error {{not superset}} expected-error {{incompatible type}}
  37. void (&t2)() throw() = s2; // expected-error {{not superset}}
  38. void (*t3)() throw(int) = &s2; // valid
  39. void (*t4)() throw(A) = &s1; // valid
  40. t4 = &s3; // valid
  41. t4 = &s4; // valid
  42. t4 = &s5; // expected-error {{not superset}} expected-error {{incompatible type}}
  43. void (*t5)() = &s1; // valid
  44. t5 = &s2; // valid
  45. t5 = &s6; // valid
  46. t5 = &s7; // valid
  47. t1 = t3; // expected-error {{not superset}} expected-error {{incompatible type}}
  48. t3 = t1; // valid
  49. void (*t6)() throw(B1);
  50. t6 = t4; // expected-error {{not superset}} expected-error {{incompatible type}}
  51. t4 = t6; // valid
  52. t5 = t1; // valid
  53. t1 = t5; // expected-error {{not superset}} expected-error {{incompatible type}}
  54. // return types and arguments must match exactly, no inheritance allowed
  55. void (*(*t7)())() throw(B1) = &s8; // valid
  56. void (*(*t8)())() throw(A) = &s8; // expected-error {{return types differ}}
  57. void (*(*t9)())() throw(D) = &s8; // expected-error {{return types differ}}
  58. void (*t10)(void (*)() throw(B1)) = &s9; // valid
  59. void (*t11)(void (*)() throw(A)) = &s9; // expected-error {{argument types differ}}
  60. void (*t12)(void (*)() throw(D)) = &s9; // expected-error {{argument types differ}}
  61. }
  62. // Member function stuff
  63. struct Str1 { void f() throw(int); }; // expected-note {{previous declaration}}
  64. void Str1::f() // expected-warning {{missing exception specification}}
  65. {
  66. }
  67. void mfnptr()
  68. {
  69. void (Str1::*pfn1)() throw(int) = &Str1::f; // valid
  70. void (Str1::*pfn2)() = &Str1::f; // valid
  71. void (Str1::*pfn3)() throw() = &Str1::f; // expected-error {{not superset}}
  72. }