From 5d8103ae7d8317484c2cb2e75edb37b1cc8d4d1b Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Tue, 26 Sep 2017 18:20:39 +0000 Subject: [PATCH] [Sema] Corrected the warn-on-throw-from-noexcept behavior to include nothrow 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 | 2 +- test/SemaCXX/warn-throw-out-noexcept-func.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 0b48838474..08fc0802c6 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -426,7 +426,7 @@ static void checkThrowInNonThrowingFunc(Sema &S, const FunctionDecl *FD, static bool isNoexcept(const FunctionDecl *FD) { const auto *FPT = FD->getType()->castAs(); - if (FPT->isNothrow(FD->getASTContext())) + if (FPT->isNothrow(FD->getASTContext()) || FD->hasAttr()) return true; return false; } diff --git a/test/SemaCXX/warn-throw-out-noexcept-func.cpp b/test/SemaCXX/warn-throw-out-noexcept-func.cpp index 67ffbd9394..5e1c571449 100644 --- a/test/SemaCXX/warn-throw-out-noexcept-func.cpp +++ b/test/SemaCXX/warn-throw-out-noexcept-func.cpp @@ -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 { -- 2.40.0