diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 5 | ||||
-rw-r--r-- | clang/test/Sema/return-noreturn.c | 8 |
2 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 11dbf042f25..70cab66d87c 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1150,6 +1150,7 @@ void Sema::CheckFallThroughForFunctionDef(Decl *D, Stmt *Body) { // which this code would then warn about. if (getDiagnostics().hasErrorOccurred()) return; + bool ReturnsVoid = false; bool HasNoReturn = false; if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { @@ -1192,7 +1193,7 @@ void Sema::CheckFallThroughForFunctionDef(Decl *D, Stmt *Body) { Diag(Compound->getRBracLoc(), diag::warn_falloff_nonvoid_function); break; case NeverFallThrough: - if (ReturnsVoid) + if (ReturnsVoid && !HasNoReturn) Diag(Compound->getLBracLoc(), diag::warn_suggest_noreturn_function); break; } @@ -1214,7 +1215,7 @@ void Sema::CheckFallThroughForBlock(QualType BlockTy, Stmt *Body) { return; bool ReturnsVoid = false; bool HasNoReturn = false; - if (const FunctionType *FT = BlockTy->getPointeeType()->getAs<FunctionType>()) { + if (const FunctionType *FT =BlockTy->getPointeeType()->getAs<FunctionType>()){ if (FT->getResultType()->isVoidType()) ReturnsVoid = true; if (FT->getNoReturnAttr()) diff --git a/clang/test/Sema/return-noreturn.c b/clang/test/Sema/return-noreturn.c index e2452f407f4..8868c9ee0ae 100644 --- a/clang/test/Sema/return-noreturn.c +++ b/clang/test/Sema/return-noreturn.c @@ -27,3 +27,11 @@ __attribute__((__noreturn__)) void* test3(int arg) { __attribute__((__noreturn__)) void* test3_positive(int arg) { while (0) foo_test_3(); } // expected-warning{{function declared 'noreturn' should not return}} + + +// PR5298 - -Wmissing-noreturn shouldn't warn if the function is already +// declared noreturn. +void __attribute__((noreturn)) +test4() { + test2_positive(); +} |