42 lines · cpp
1// RUN: %clang_cc1 -std=c++11 %s -verify -fcxx-exceptions2 3// We permit overriding an implicit exception specification with an explicit one4// as an extension, for compatibility with existing code.5 6struct S {7 void a(); // expected-note {{here}}8 ~S(); // expected-note {{here}}9 void operator delete(void*); // expected-note {{here}}10};11 12void S::a() noexcept {} // expected-error {{does not match previous}}13S::~S() noexcept {} // expected-warning {{function previously declared with an implicit exception specification redeclared with an explicit exception specification}}14void S::operator delete(void*) noexcept {} // expected-warning {{function previously declared with an implicit exception specification redeclared with an explicit exception specification}}15 16struct 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 22void T::a() {} // expected-error {{missing exception specification 'noexcept'}}23T::~T() {} // expected-warning {{function previously declared with an explicit exception specification redeclared with an implicit exception specification}}24void 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 29template<typename T> struct U {30 T t;31 ~U(); // expected-note {{here}}32 void operator delete(void*); // expected-note {{here}}33};34 35template<typename T> U<T>::~U() noexcept(true) {} // expected-error {{exception specification in declaration does not match previous declaration}}36template<typename T> void U<T>::operator delete(void*) noexcept(false) {} // expected-error {{exception specification in declaration does not match previous declaration}}37 38 39// Make sure this restriction interacts properly with __attribute__((noreturn))40void __attribute__ ((__noreturn__)) PR17110(int status) throw();41void PR17110(int status) throw();42