p4.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // RUN: %clang_cc1 -std=c++11 %s -verify -fcxx-exceptions
  2. // We permit overriding an implicit exception specification with an explicit one
  3. // as an extension, for compatibility with existing code.
  4. struct S {
  5. void a(); // expected-note {{here}}
  6. ~S(); // expected-note {{here}}
  7. void operator delete(void*); // expected-note {{here}}
  8. };
  9. void S::a() noexcept {} // expected-error {{does not match previous}}
  10. S::~S() noexcept {} // expected-warning {{function previously declared with an implicit exception specification redeclared with an explicit exception specification}}
  11. void S::operator delete(void*) noexcept {} // expected-warning {{function previously declared with an implicit exception specification redeclared with an explicit exception specification}}
  12. struct T {
  13. void a() noexcept; // expected-note {{here}}
  14. ~T() noexcept; // expected-note {{here}}
  15. void operator delete(void*) noexcept; // expected-note {{here}}
  16. };
  17. void T::a() {} // expected-warning {{missing exception specification 'noexcept'}}
  18. T::~T() {} // expected-warning {{function previously declared with an explicit exception specification redeclared with an implicit exception specification}}
  19. void T::operator delete(void*) {} // expected-warning {{function previously declared with an explicit exception specification redeclared with an implicit exception specification}}
  20. // The extension does not extend to function templates.
  21. template<typename T> struct U {
  22. T t;
  23. ~U(); // expected-note {{here}}
  24. void operator delete(void*); // expected-note {{here}}
  25. };
  26. template<typename T> U<T>::~U() noexcept(true) {} // expected-error {{exception specification in declaration does not match previous declaration}}
  27. template<typename T> void U<T>::operator delete(void*) noexcept(false) {} // expected-error {{exception specification in declaration does not match previous declaration}}
  28. // Make sure this restriction interacts properly with __attribute__((noreturn))
  29. void __attribute__ ((__noreturn__)) PR17110(int status) throw();
  30. void PR17110(int status) throw();