[cfe-commits] r134138 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaStmt.cpp

Chandler Carruth chandlerc at gmail.com
Thu Jun 30 01:56:22 PDT 2011


Author: chandlerc
Date: Thu Jun 30 03:56:22 2011
New Revision: 134138

URL: http://llvm.org/viewvc/llvm-project?rev=134138&view=rev
Log:
Improve the wording of the warning when returning a value from
a constructor or destructor.

Patch by Hans Wennborg.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=134138&r1=134137&r2=134138&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jun 30 03:56:22 2011
@@ -4189,8 +4189,9 @@
   "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<

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=134138&r1=134137&r2=134138&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu Jun 30 03:56:22 2011
@@ -1761,8 +1761,17 @@
         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();
         }
       }





More information about the cfe-commits mailing list