[cfe-commits] r161324 - in /cfe/trunk: 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

Dmitri Gribenko gribozavr at gmail.com
Mon Aug 6 09:29:26 PDT 2012


Author: gribozavr
Date: Mon Aug  6 11:29:26 2012
New Revision: 161324

URL: http://llvm.org/viewvc/llvm-project?rev=161324&view=rev
Log:
Comment diagnostics: \return in void function: specialize diagnostic text for
ObjC methods.

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

Modified: cfe/trunk/include/clang/AST/Comment.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Comment.h?rev=161324&r1=161323&r2=161324&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Comment.h (original)
+++ cfe/trunk/include/clang/AST/Comment.h Mon Aug  6 11:29:26 2012
@@ -979,6 +979,9 @@
   /// 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.

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td?rev=161324&r1=161323&r2=161324&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td Mon Aug  6 11:29:26 2012
@@ -102,12 +102,13 @@
 
 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

Modified: cfe/trunk/lib/AST/Comment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Comment.cpp?rev=161324&r1=161323&r2=161324&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Comment.cpp (original)
+++ cfe/trunk/lib/AST/Comment.cpp Mon Aug  6 11:29:26 2012
@@ -145,6 +145,7 @@
   IsTemplateDecl = false;
   IsTemplateSpecialization = false;
   IsTemplatePartialSpecialization = false;
+  IsObjCMethod = false;
   IsInstanceMethod = false;
   IsClassMethod = false;
   ParamVars = ArrayRef<const ParmVarDecl *>();
@@ -193,6 +194,7 @@
     ParamVars = ArrayRef<const ParmVarDecl *>(MD->param_begin(),
                                               MD->param_size());
     ResultType = MD->getResultType();
+    IsObjCMethod = true;
     IsInstanceMethod = MD->isInstanceMethod();
     IsClassMethod = !IsInstanceMethod;
     break;

Modified: cfe/trunk/lib/AST/CommentSema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentSema.cpp?rev=161324&r1=161323&r2=161324&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentSema.cpp (original)
+++ cfe/trunk/lib/AST/CommentSema.cpp Mon Aug  6 11:29:26 2012
@@ -481,7 +481,10 @@
       unsigned DiagKind;
       switch (ThisDeclInfo->ThisDecl->getKind()) {
       default:
-        DiagKind = 0;
+        if (ThisDeclInfo->IsObjCMethod)
+          DiagKind = 3;
+        else
+          DiagKind = 0;
         break;
       case Decl::CXXConstructor:
         DiagKind = 1;

Modified: cfe/trunk/test/Sema/warn-documentation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.cpp?rev=161324&r1=161323&r2=161324&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-documentation.cpp (original)
+++ cfe/trunk/test/Sema/warn-documentation.cpp Mon Aug  6 11:29:26 2012
@@ -286,37 +286,37 @@
 template<typename T>
 T test_returns_right_decl_5(T aaa);
 
-// expected-warning at +1 {{'\returns' command used in a comment that is not attached to a function declaration}}
+// expected-warning at +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 at +1 {{'\return' command used in a comment that is not attached to a function declaration}}
+// expected-warning at +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 at +1 {{'\result' command used in a comment that is not attached to a function declaration}}
+// expected-warning at +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 at +1 {{'\returns' command used in a comment that is attached to a void function}}
+// expected-warning at +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 at +1 {{'\returns' command used in a comment that is attached to a void function}}
+// expected-warning at +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 at +1 {{'\returns' command used in a comment that is attached to a void function}}
+// expected-warning at +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 at +1 {{'\returns' command used in a comment that is not attached to a function declaration}}
+// expected-warning at +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 at +1 {{'\returns' command used in a comment that is not attached to a function declaration}}
+// expected-warning at +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 at +1 {{'\returns' command used in a comment that is attached to a constructor}}
@@ -328,15 +328,15 @@
   ~test_returns_wrong_decl_7();
 };
 
-// expected-warning at +1 {{'\returns' command used in a comment that is not attached to a function declaration}}
+// expected-warning at +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 at +1 {{'\returns' command used in a comment that is not attached to a function declaration}}
+  // expected-warning at +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 at +1 {{'\returns' command used in a comment that is not attached to a function declaration}}
+// expected-warning at +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 { };
 

Modified: cfe/trunk/test/Sema/warn-documentation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.m?rev=161324&r1=161323&r2=161324&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-documentation.m (original)
+++ cfe/trunk/test/Sema/warn-documentation.m Mon Aug  6 11:29:26 2012
@@ -82,3 +82,12 @@
 
 int b;
 
+ at interface TestReturns1
+/// \returns Aaa
+- (int)test1:(NSString *)aaa;
+
+// expected-warning at +1 {{'\returns' command used in a comment that is attached to a method returning void}}
+/// \returns Aaa
+- (void)test2:(NSString *)aaa;
+ at end
+





More information about the cfe-commits mailing list