p1.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
  2. // Simple parser tests, dynamic specification.
  3. namespace dyn {
  4. struct X { };
  5. struct Y { };
  6. void f() throw() { }
  7. void g(int) throw(X) { }
  8. void h() throw(X, Y) { }
  9. class Class {
  10. void foo() throw (X, Y) { }
  11. };
  12. void (*fptr)() throw();
  13. }
  14. // Simple parser tests, noexcept specification.
  15. namespace noex {
  16. void f1() noexcept { }
  17. void f2() noexcept (true) { }
  18. void f3() noexcept (false) { }
  19. void f4() noexcept (1 < 2) { }
  20. class CA1 {
  21. void foo() noexcept { }
  22. void bar() noexcept (true) { }
  23. };
  24. void (*fptr1)() noexcept;
  25. void (*fptr2)() noexcept (true);
  26. }
  27. namespace mix {
  28. void f() throw(int) noexcept { } // expected-error {{cannot have both}}
  29. void g() noexcept throw(int) { } // expected-error {{cannot have both}}
  30. }
  31. // Sema tests, noexcept specification
  32. namespace noex {
  33. struct A {};
  34. void g1() noexcept(A()); // expected-error {{not contextually convertible}}
  35. 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}}
  36. }
  37. namespace noexcept_unevaluated {
  38. template<typename T> bool f(T) {
  39. T* x = 1;
  40. }
  41. template<typename T>
  42. void g(T x) noexcept((sizeof(T) == sizeof(int)) || noexcept(f(x))) { }
  43. void h() {
  44. g(1);
  45. }
  46. }
  47. namespace PR11084 {
  48. template<int X> struct A {
  49. static int f() noexcept(1/X) { return 10; } // expected-error{{argument to noexcept specifier must be a constant expression}} expected-note{{division by zero}}
  50. };
  51. template<int X> void f() {
  52. int (*p)() noexcept(1/X); // expected-error{{argument to noexcept specifier must be a constant expression}} expected-note{{division by zero}}
  53. };
  54. void g() {
  55. A<0>::f(); // expected-note{{in instantiation of exception specification for 'f'}}
  56. f<0>(); // expected-note{{in instantiation of function template specialization}}
  57. }
  58. }