static void EmitDiagForCXXThrowInNonThrowingFunc(Sema &S, SourceLocation OpLoc,
const FunctionDecl *FD) {
- if (!S.getSourceManager().isInSystemHeader(OpLoc)) {
+ if (!S.getSourceManager().isInSystemHeader(OpLoc) &&
+ FD->getTypeSourceInfo()) {
S.Diag(OpLoc, diag::warn_throw_in_noexcept_func) << FD;
if (S.getLangOpts().CPlusPlus11 &&
(isa<CXXDestructorDecl>(FD) ||
FD->getDeclName().getCXXOverloadedOperator() == OO_Delete ||
- FD->getDeclName().getCXXOverloadedOperator() == OO_Array_Delete))
- S.Diag(FD->getLocation(), diag::note_throw_in_dtor);
- else
- S.Diag(FD->getLocation(), diag::note_throw_in_function);
+ FD->getDeclName().getCXXOverloadedOperator() == OO_Array_Delete)) {
+ if (const auto *Ty = FD->getTypeSourceInfo()->getType()->
+ getAs<FunctionProtoType>())
+ S.Diag(FD->getLocation(), diag::note_throw_in_dtor)
+ << !isa<CXXDestructorDecl>(FD) << !Ty->hasExceptionSpec()
+ << FD->getExceptionSpecSourceRange();
+ } else
+ S.Diag(FD->getLocation(), diag::note_throw_in_function)
+ << FD->getExceptionSpecSourceRange();
}
}
static bool isNoexcept(const FunctionDecl *FD) {
const auto *FPT = FD->getType()->castAs<FunctionProtoType>();
- if (FPT->getExceptionSpecType() != EST_None &&
- FPT->isNothrow(FD->getASTContext()))
+ if (FPT->isNothrow(FD->getASTContext()))
return true;
return false;
}
struct A_ShouldDiag {
~A_ShouldDiag(); // implicitly noexcept(true)
};
-A_ShouldDiag::~A_ShouldDiag() { // expected-note {{destructor or deallocator has a (possibly implicit) non-throwing excepton specification}}
- throw 1; // expected-warning {{has a non-throwing exception specification but can still throw, resulting in unexpected program termination}}
+A_ShouldDiag::~A_ShouldDiag() { // expected-note {{destructor has a implicit non-throwing exception specification}}
+ throw 1; // expected-warning {{has a non-throwing exception specification but can still throw}}
}
struct B_ShouldDiag {
int i;
};
struct R_ShouldDiag : A_ShouldDiag {
B_ShouldDiag b;
- ~R_ShouldDiag() { // expected-note {{destructor or deallocator has a}}
+ ~R_ShouldDiag() { // expected-note {{destructor has a implicit non-throwing exception specification}}
throw 1; // expected-warning {{has a non-throwing exception specification but}}
}
};
~N_ShouldDiag(); //implicitly noexcept(true)
};
-N_ShouldDiag::~N_ShouldDiag() { // expected-note {{destructor or deallocator has a}}
+N_ShouldDiag::~N_ShouldDiag() { // expected-note {{destructor has a implicit non-throwing exception specification}}
throw 1; // expected-warning {{has a non-throwing exception specification but}}
}
struct X_ShouldDiag {
B_ShouldDiag b;
- ~X_ShouldDiag() noexcept { // expected-note {{destructor or deallocator has a}}
- throw 1; // expected-warning {{has a non-throwing exception specification but}}
+ ~X_ShouldDiag() noexcept { // expected-note {{destructor has a non-throwing exception}}
+ throw 1; // expected-warning {{has a non-throwing exception specification but}}
}
};
struct Y_ShouldDiag : A_ShouldDiag {
- ~Y_ShouldDiag() noexcept(true) { // expected-note {{destructor or deallocator has a}}
- throw 1; // expected-warning {{has a non-throwing exception specification but}}
+ ~Y_ShouldDiag() noexcept(true) { // expected-note {{destructor has a non-throwing exception specification}}
+ throw 1; // expected-warning {{has a non-throwing exception specification but}}
}
};
struct C_ShouldNotDiag {
throw 1;
}
};
-struct E_ShouldNotDiag {
+struct E_ShouldNotDiag {
C_ShouldNotDiag c;
~E_ShouldNotDiag(); //implicitly noexcept(false)
};
T b;
public:
- ~A1_ShouldDiag() { // expected-note {{destructor or deallocator has a}}
+ ~A1_ShouldDiag() { // expected-note {{destructor has a implicit non-throwing exception specification}}
throw 1; // expected-warning {{has a non-throwing exception specification but}}
}
};
struct R1_ShouldDiag : A1_ShouldDiag<T> //expected-note {{in instantiation of member function}}
{
B1_ShouldDiag<T> b;
- ~R1_ShouldDiag() { // expected-note {{destructor or deallocator has a}}
+ ~R1_ShouldDiag() { // expected-note {{destructor has a implicit non-throwing exception specification}}
throw 1; // expected-warning {{has a non-throwing exception specification but}}
}
};
template <typename T>
struct S1_ShouldDiag : A1_ShouldDiag<T> {
B1_ShouldDiag<T> b;
- ~S1_ShouldDiag() noexcept { // expected-note {{destructor or deallocator has a}}
- throw 1; // expected-warning {{has a non-throwing exception specification but}}
+ ~S1_ShouldDiag() noexcept { // expected-note {{destructor has a non-throwing exception specification}}
+ throw 1; // expected-warning {{has a non-throwing exception specification but}}
}
};
-void operator delete(void *ptr) noexcept { // expected-note {{destructor or deallocator has a}}
- throw 1; // expected-warning {{has a non-throwing exception specification but}}
+void operator delete(void *ptr) noexcept { // expected-note {{deallocator has a non-throwing exception specification}}
+ throw 1; // expected-warning {{has a non-throwing exception specification but}}
}
struct except_fun {
static const bool i = false;
};
template <typename T>
struct dependent_warn_noexcept {
- ~dependent_warn_noexcept() noexcept(T::i) { // expected-note {{destructor or deallocator has a}}
- throw 1; // expected-warning {{has a non-throwing exception specification but}}
+ ~dependent_warn_noexcept() noexcept(T::i) { // expected-note {{destructor has a non-throwing exception specification}}
+ throw 1; // expected-warning {{has a non-throwing exception specification but}}
}
};
template <typename T>
struct dependent_warn_both {
- ~dependent_warn_both() noexcept(T::i) { // expected-note {{destructor or deallocator has a}}
- throw 1; // expected-warning {{has a non-throwing exception specification but}}
+ ~dependent_warn_both() noexcept(T::i) { // expected-note {{destructor has a non-throwing exception specification}}
+ throw 1; // expected-warning {{has a non-throwing exception specification but}}
}
};
-void foo() noexcept { //expected-note {{non-throwing function declare here}}
- throw 1; // expected-warning {{has a non-throwing exception specification but}}
+void foo() noexcept { //expected-note {{function declared non-throwing here}}
+ throw 1; // expected-warning {{has a non-throwing exception specification but}}
}
struct Throws {
~Throws() noexcept(false);
struct ShouldDiagnose {
Throws T;
- ~ShouldDiagnose() noexcept { //expected-note {{destructor or deallocator has a}}
+ ~ShouldDiagnose() noexcept { //expected-note {{destructor has a non-throwing exception specification}}
throw; // expected-warning {{has a non-throwing exception specification but}}
}
};
struct ShouldNotDiagnose {
Throws T;
- ~ShouldNotDiagnose() {
- throw;
+ ~ShouldNotDiagnose() {
+ throw;
}
};
}
}
-void h_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}}
+void h_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
try {
throw 12; // expected-warning {{has a non-throwing exception specification but}}
} catch (const char *) {
}
}
-void i_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}}
+void i_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
try {
throw 12;
} catch (int) {
throw; // expected-warning {{has a non-throwing exception specification but}}
}
}
-void j_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}}
+void j_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
try {
throw 12;
} catch (int) {
}
}
-void k_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}}
+void k_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
try {
throw 12;
} catch (...) {
}
}
-void loo_ShouldDiag(int i) noexcept { //expected-note {{non-throwing function declare here}}
+void loo_ShouldDiag(int i) noexcept { //expected-note {{function declared non-throwing here}}
if (i)
try {
throw 12;
throw 12;
}
-void loo2_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}}
+void loo2_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
if (1)
throw 12; // expected-warning {{has a non-throwing exception specification but}}
}
struct S {};
-void l_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}}
+void l_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
try {
throw S{}; //expected-warning {{has a non-throwing exception specification but}}
} catch (S *s) {
throw s;
} catch (S s) {
}
-
}
void n_ShouldNotDiag() noexcept {
try {
} catch (const S &s) {
}
}
-void o_ShouldDiag() noexcept { //expected-note {{non-throwing function declare here}}
+void o_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
try {
throw; //expected-warning {{has a non-throwing exception specification but}}
} catch (...) {
}
#define NOEXCEPT noexcept
-void with_macro() NOEXCEPT { //expected-note {{non-throwing function declare here}}
+void with_macro() NOEXCEPT { //expected-note {{function declared non-throwing here}}
throw 1; // expected-warning {{has a non-throwing exception specification but}}
}
} catch (...) {
}
-void with_try_block1() noexcept try { //expected-note {{non-throwing function declare here}}
- throw 2; // expected-warning {{has a non-throwing exception specification but}}
+void with_try_block1() noexcept try { //expected-note {{function declared non-throwing here}}
+ throw 2; // expected-warning {{has a non-throwing exception specification but}}
} catch (char *) {
}
throw &d;
} catch (B *) {}
}
-void badPlain() noexcept { // expected-note {{non-throwing function declare here}}
+void badPlain() noexcept { //expected-note {{function declared non-throwing here}}
try {
- throw B(); // expected-warning {{'badPlain' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}}
+ throw B(); // expected-warning {{'badPlain' has a non-throwing exception specification but can still throw}}
} catch (D) {}
}
-void badReference() noexcept { // expected-note {{non-throwing function declare here}}
+void badReference() noexcept { //expected-note {{function declared non-throwing here}}
try {
- throw B(); // expected-warning {{'badReference' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}}
+ throw B(); // expected-warning {{'badReference' has a non-throwing exception specification but can still throw}}
} catch (D &) {}
}
-void badPointer() noexcept { // expected-note {{non-throwing function declare here}}
+void badPointer() noexcept { //expected-note {{function declared non-throwing here}}
B b;
try {
- throw &b; // expected-warning {{'badPointer' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}}
+ throw &b; // expected-warning {{'badPointer' has a non-throwing exception specification but can still throw}}
} catch (D *) {}
}
}