]> granicus.if.org Git - clang/commitdiff
[Sema] Corrected the warn-on-throw-from-noexcept behavior to include nothrow
authorErich Keane <erich.keane@intel.com>
Tue, 26 Sep 2017 18:20:39 +0000 (18:20 +0000)
committerErich Keane <erich.keane@intel.com>
Tue, 26 Sep 2017 18:20:39 +0000 (18:20 +0000)
Discovered that 'nothrow' (which is supposed to be an alias for noexcept)
was not warning with a throw inside of it. This patch corrects the behavior
previously created to add 'nothrow' to this list.

Differential Revision: https://reviews.llvm.org/D38203

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314229 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/AnalysisBasedWarnings.cpp
test/SemaCXX/warn-throw-out-noexcept-func.cpp

index 0b48838474aed83a687d544592af46a0909246cb..08fc0802c6e72a1a46f60e8c9312bb4f0f7c78b7 100644 (file)
@@ -426,7 +426,7 @@ static void checkThrowInNonThrowingFunc(Sema &S, const FunctionDecl *FD,
 
 static bool isNoexcept(const FunctionDecl *FD) {
   const auto *FPT = FD->getType()->castAs<FunctionProtoType>();
-  if (FPT->isNothrow(FD->getASTContext()))
+  if (FPT->isNothrow(FD->getASTContext()) || FD->hasAttr<NoThrowAttr>())
     return true;
   return false;
 }
index 67ffbd93940a8c551880232f558ed37c7ce26410..5e1c5714496ce3a49c98a63fea15b9a3b25ff981 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s  -fdelayed-template-parsing -fcxx-exceptions -fsyntax-only -Wexceptions -verify -std=c++11
+// RUN: %clang_cc1 %s  -fdelayed-template-parsing -fcxx-exceptions -fsyntax-only -Wexceptions -verify -fdeclspec -std=c++11
 struct A_ShouldDiag {
   ~A_ShouldDiag(); // implicitly noexcept(true)
 };
@@ -14,6 +14,15 @@ struct R_ShouldDiag : A_ShouldDiag {
   ~R_ShouldDiag() { // expected-note  {{destructor has a implicit non-throwing exception specification}}
     throw 1; // expected-warning {{has a non-throwing exception specification but}}
   }
+  __attribute__((nothrow)) R_ShouldDiag() {// expected-note {{function declared non-throwing here}}
+    throw 1;// expected-warning {{has a non-throwing exception specification but}}
+  }
+  void __attribute__((nothrow)) SomeThrow() {// expected-note {{function declared non-throwing here}}
+   throw 1; // expected-warning {{has a non-throwing exception specification but}}
+  }
+  void __declspec(nothrow) SomeDeclspecThrow() {// expected-note {{function declared non-throwing here}}
+   throw 1; // expected-warning {{has a non-throwing exception specification but}}
+  }
 };
 
 struct M_ShouldNotDiag {