Improve the wording of the warning when returning a value from

a constructor or destructor.

Patch by Hans Wennborg.

llvm-svn: 134138
This commit is contained in:
Chandler Carruth 2011-06-30 08:56:22 +00:00
parent d9dfe3a1f8
commit 1406d6c037
2 changed files with 13 additions and 3 deletions

View File

@ -4189,8 +4189,9 @@ def ext_return_missing_expr : ExtWarn<
"non-void %select{function|method}1 %0 should return a value">, DefaultError,
InGroup<ReturnType>;
def ext_return_has_expr : ExtWarn<
"void %select{function|method}1 %0 should not return a value">, DefaultError,
InGroup<ReturnType>;
"%select{void function|void method|constructor|destructor}1 %0 "
"should not return a value">,
DefaultError, InGroup<ReturnType>;
def ext_return_has_void_expr : Extension<
"void %select{function|method}1 %0 should not return void expression">;
def warn_noreturn_function_has_return_expr : Warning<

View File

@ -1761,8 +1761,17 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) {
if (D != diag::ext_return_has_void_expr ||
!getLangOptions().CPlusPlus) {
NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
int FunctionKind = 0;
if (isa<ObjCMethodDecl>(CurDecl))
FunctionKind = 1;
else if (isa<CXXConstructorDecl>(CurDecl))
FunctionKind = 2;
else if (isa<CXXDestructorDecl>(CurDecl))
FunctionKind = 3;
Diag(ReturnLoc, D)
<< CurDecl->getDeclName() << isa<ObjCMethodDecl>(CurDecl)
<< CurDecl->getDeclName() << FunctionKind
<< RetValExp->getSourceRange();
}
}