]> granicus.if.org Git - clang/commitdiff
Comment diagnostics: \return in void function: specialize diagnostic text for
authorDmitri Gribenko <gribozavr@gmail.com>
Mon, 6 Aug 2012 16:29:26 +0000 (16:29 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Mon, 6 Aug 2012 16:29:26 +0000 (16:29 +0000)
ObjC methods.

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

include/clang/AST/Comment.h
include/clang/Basic/DiagnosticCommentKinds.td
lib/AST/Comment.cpp
lib/AST/CommentSema.cpp
test/Sema/warn-documentation.cpp
test/Sema/warn-documentation.m

index b1f6519631781cd8bdeb04e4627aceeb12740565..6006d8d2998ff2831b16c4198be7e54873ebee44 100644 (file)
@@ -979,6 +979,9 @@ struct DeclInfo {
   /// Never true if \c IsFunctionDecl is true.
   unsigned IsTemplatePartialSpecialization : 1;
 
+  /// Is \c ThisDecl an ObjCMethodDecl.
+  unsigned IsObjCMethod : 1;
+
   /// Is \c ThisDecl a non-static member function of C++ class or
   /// instance method of ObjC class.
   /// Can be true only if \c IsFunctionDecl is true.
index 7c13644926daf55ec194a4730f305adce1d00c92..1594c313d7cb025ba95d81f48eb20d500996cb73 100644 (file)
@@ -102,12 +102,13 @@ def note_doc_tparam_name_suggestion : Note<
 
 def warn_doc_returns_not_attached_to_a_function_decl : Warning<
   "'\\%0' command used in a comment that is not attached to "
-  "a function declaration">,
+  "a function or method declaration">,
   InGroup<Documentation>, DefaultIgnore;
 
 def warn_doc_returns_attached_to_a_void_function : Warning<
   "'\\%0' command used in a comment that is attached to a "
-  "%select{void function|constructor|destructor}1">,
+  "%select{function returning void|constructor|destructor|"
+  "method returning void}1">,
   InGroup<Documentation>, DefaultIgnore;
 
 } // end of documentation issue category
index ac224ccecd3e0e55c6b58f9e5ea5aa390e86ca2c..e35b2a3d5e088a94583e028a16188f51d20808bf 100644 (file)
@@ -145,6 +145,7 @@ void DeclInfo::fill() {
   IsTemplateDecl = false;
   IsTemplateSpecialization = false;
   IsTemplatePartialSpecialization = false;
+  IsObjCMethod = false;
   IsInstanceMethod = false;
   IsClassMethod = false;
   ParamVars = ArrayRef<const ParmVarDecl *>();
@@ -193,6 +194,7 @@ void DeclInfo::fill() {
     ParamVars = ArrayRef<const ParmVarDecl *>(MD->param_begin(),
                                               MD->param_size());
     ResultType = MD->getResultType();
+    IsObjCMethod = true;
     IsInstanceMethod = MD->isInstanceMethod();
     IsClassMethod = !IsInstanceMethod;
     break;
index c8422508d38174df7470c88bacec4d418af04eb4..770d5bba244f8a7f92266b5f1aabf84a891f3e78 100644 (file)
@@ -481,7 +481,10 @@ void Sema::checkReturnsCommand(const BlockCommandComment *Command) {
       unsigned DiagKind;
       switch (ThisDeclInfo->ThisDecl->getKind()) {
       default:
-        DiagKind = 0;
+        if (ThisDeclInfo->IsObjCMethod)
+          DiagKind = 3;
+        else
+          DiagKind = 0;
         break;
       case Decl::CXXConstructor:
         DiagKind = 1;
index addbc6a09fa9b577260963ce3327b3f7a8fac091..19d43ab488fe27668a07ab408492b203bd2606f8 100644 (file)
@@ -286,37 +286,37 @@ int test_returns_right_decl_4(int aaa);
 template<typename T>
 T test_returns_right_decl_5(T aaa);
 
-// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function declaration}}
+// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
 /// \returns Aaa
 int test_returns_wrong_decl_1;
 
-// expected-warning@+1 {{'\return' command used in a comment that is not attached to a function declaration}}
+// expected-warning@+1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
 /// \return Aaa
 int test_returns_wrong_decl_2;
 
-// expected-warning@+1 {{'\result' command used in a comment that is not attached to a function declaration}}
+// expected-warning@+1 {{'\result' command used in a comment that is not attached to a function or method declaration}}
 /// \result Aaa
 int test_returns_wrong_decl_3;
 
-// expected-warning@+1 {{'\returns' command used in a comment that is attached to a void function}}
+// expected-warning@+1 {{'\returns' command used in a comment that is attached to a function returning void}}
 /// \returns Aaa
 void test_returns_wrong_decl_4(int);
 
-// expected-warning@+1 {{'\returns' command used in a comment that is attached to a void function}}
+// expected-warning@+1 {{'\returns' command used in a comment that is attached to a function returning void}}
 /// \returns Aaa
 template<typename T>
 void test_returns_wrong_decl_5(T aaa);
 
-// expected-warning@+1 {{'\returns' command used in a comment that is attached to a void function}}
+// expected-warning@+1 {{'\returns' command used in a comment that is attached to a function returning void}}
 /// \returns Aaa
 template<>
 void test_returns_wrong_decl_5(int aaa);
 
-// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function declaration}}
+// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
 /// \returns Aaa
 struct test_returns_wrong_decl_6 { };
 
-// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function declaration}}
+// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
 /// \returns Aaa
 class test_returns_wrong_decl_7 {
   // expected-warning@+1 {{'\returns' command used in a comment that is attached to a constructor}}
@@ -328,15 +328,15 @@ class test_returns_wrong_decl_7 {
   ~test_returns_wrong_decl_7();
 };
 
-// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function declaration}}
+// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
 /// \returns Aaa
 enum test_returns_wrong_decl_8 {
-  // expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function declaration}}
+  // expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
   /// \returns Aaa
   test_returns_wrong_decl_9
 };
 
-// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function declaration}}
+// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
 /// \returns Aaa
 namespace test_returns_wrong_decl_10 { };
 
index 4b6aac3b496461f6c2ce31d710074b5ab0ae1cb0..7b6361c1f4008d6709a7a8dc4810c10cee57fda5 100644 (file)
@@ -82,3 +82,12 @@ int a;
 
 int b;
 
+@interface TestReturns1
+/// \returns Aaa
+- (int)test1:(NSString *)aaa;
+
+// expected-warning@+1 {{'\returns' command used in a comment that is attached to a method returning void}}
+/// \returns Aaa
+- (void)test2:(NSString *)aaa;
+@end
+