"void %select{function|method}1 %0 should not return a value">;
def ext_return_has_void_expr : Extension<
"void %select{function|method}1 %0 should not return void expression">;
+def err_noreturn_function_has_return_expr : Error<
+ "function %0 declared 'noreturn' should not return">;
def err_shufflevector_non_vector : Error<
"first two arguments to __builtin_shufflevector must be vectors">;
return ActOnBlockReturnStmt(ReturnLoc, RetValExp);
QualType FnRetType;
- if (FunctionDecl *FD = getCurFunctionDecl())
+ if (const FunctionDecl *FD = getCurFunctionDecl()) {
FnRetType = FD->getResultType();
- else if (ObjCMethodDecl *MD = getCurMethodDecl())
+ if (FD->hasAttr<NoReturnAttr>()) {
+ Diag(ReturnLoc, diag::err_noreturn_function_has_return_expr)
+ << getCurFunctionOrMethodDecl()->getDeclName();
+ return StmtError();
+ }
+ } else if (ObjCMethodDecl *MD = getCurMethodDecl())
FnRetType = MD->getResultType();
else // If we don't have a function/method context, bail.
return StmtError();
int g0 __attribute__((noreturn)); // expected-warning {{'noreturn' attribute only applies to function types}}
int f2() __attribute__((noreturn(1, 2))); // expected-error {{attribute requires 0 argument(s)}}
+
+void f3() __attribute__((noreturn));
+
+void f3() {
+ return; // expected-error {{function 'f3' declared 'noreturn' should not return}}
+}
+