]> granicus.if.org Git - clang/commitdiff
Improve the wording of the warning when returning a value from
authorChandler Carruth <chandlerc@gmail.com>
Thu, 30 Jun 2011 08:56:22 +0000 (08:56 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Thu, 30 Jun 2011 08:56:22 +0000 (08:56 +0000)
a constructor or destructor.

Patch by Hans Wennborg.

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaStmt.cpp

index 3134bdd40658f06decde8d5a8de5b17df1fc3061..f895fc7697110b5e0a369cdf4078ec1e11bcb4b5 100644 (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<
index 75124c19084b67d9465cc68a89b64587e9cc26cf..164c0ce038ecb487fb98b37f8e9c76e64d560900 100644 (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();
         }
       }