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