aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/CommentSema.h3
-rw-r--r--include/clang/Basic/DiagnosticCommentKinds.td14
-rw-r--r--lib/AST/CommentSema.cpp26
-rw-r--r--test/Sema/warn-documentation.cpp4
-rw-r--r--test/Sema/warn-documentation.m2
5 files changed, 36 insertions, 13 deletions
diff --git a/include/clang/AST/CommentSema.h b/include/clang/AST/CommentSema.h
index 7b81077b50..8eb49f65ba 100644
--- a/include/clang/AST/CommentSema.h
+++ b/include/clang/AST/CommentSema.h
@@ -206,7 +206,8 @@ public:
void resolveParamCommandIndexes(const FullComment *FC);
bool isFunctionDecl();
- bool isCallbackDecl();
+ bool isFunctionPointerVarDecl();
+ bool isObjCMethodDecl();
bool isObjCPropertyDecl();
bool isTemplateOrSpecialization();
diff --git a/include/clang/Basic/DiagnosticCommentKinds.td b/include/clang/Basic/DiagnosticCommentKinds.td
index 2ee9327816..b0aece5640 100644
--- a/include/clang/Basic/DiagnosticCommentKinds.td
+++ b/include/clang/Basic/DiagnosticCommentKinds.td
@@ -74,8 +74,18 @@ def warn_doc_param_not_attached_to_a_function_decl : Warning<
InGroup<Documentation>, DefaultIgnore;
def warn_doc_function_not_attached_to_a_function_decl : Warning<
- "'%select{\\|@}0%1' command used in a comment that is attached to a non-%2 "
- "declaration immediately following it">,
+ "'%select{\\|@}0function' command should be used in a comment attached to a "
+ "function declaration">,
+ InGroup<Documentation>, DefaultIgnore;
+
+def warn_doc_callback_not_attached_to_a_function_ptr_decl : Warning<
+ "'%select{\\|@}0callback' command should be used in a comment attached to a "
+ "pointer to function declaration">,
+ InGroup<Documentation>, DefaultIgnore;
+
+def warn_doc_method_not_attached_to_a_objc_method_decl : Warning<
+ "'%select{\\|@}0method' command should be used in a comment attached to an "
+ "objective-c method declaration">,
InGroup<Documentation>, DefaultIgnore;
def warn_doc_param_duplicate : Warning<
diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp
index bd32da6e6e..23e27a3fe5 100644
--- a/lib/AST/CommentSema.cpp
+++ b/lib/AST/CommentSema.cpp
@@ -90,12 +90,17 @@ ParamCommandComment *Sema::actOnParamCommandStart(
void Sema::checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment) {
const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
- if (Info->IsFunctionDeclarationCommand &&
- !isFunctionDecl() && !isCallbackDecl())
- Diag(Comment->getLocation(),
- diag::warn_doc_function_not_attached_to_a_function_decl)
- << Comment->getCommandMarker()
- << Info->Name << Info->Name
+ if (!Info->IsFunctionDeclarationCommand)
+ return;
+ StringRef Name = Info->Name;
+ unsigned DiagKind = llvm::StringSwitch<unsigned>(Name)
+ .Case("function", diag::warn_doc_function_not_attached_to_a_function_decl)
+ .Case("method", diag::warn_doc_method_not_attached_to_a_objc_method_decl)
+ .Case("callback", diag::warn_doc_callback_not_attached_to_a_function_ptr_decl)
+ .Default(0);
+
+ if (DiagKind)
+ Diag(Comment->getLocation(), DiagKind) << Comment->getCommandMarker()
<< Comment->getSourceRange();
}
@@ -685,8 +690,15 @@ bool Sema::isFunctionDecl() {
inspectThisDecl();
return ThisDeclInfo->getKind() == DeclInfo::FunctionKind;
}
+
+bool Sema::isObjCMethodDecl() {
+ return isFunctionDecl() && ThisDeclInfo->CurrentDecl &&
+ isa<ObjCMethodDecl>(ThisDeclInfo->CurrentDecl);
+}
-bool Sema::isCallbackDecl() {
+/// isFunctionPointerVarDecl - returns 'true' if declaration is a pointer to
+/// function decl.
+bool Sema::isFunctionPointerVarDecl() {
if (!ThisDeclInfo)
return false;
if (!ThisDeclInfo->IsFilled)
diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp
index 0e5fef823e..32e43a77f9 100644
--- a/test/Sema/warn-documentation.cpp
+++ b/test/Sema/warn-documentation.cpp
@@ -549,13 +549,13 @@ namespace test_returns_wrong_decl_10 { };
typedef unsigned int test_returns_wrong_decl_11;
// rdar://13094352
-// expected-warning@+1 {{'@function' command used in a comment that is attached to a non-function declaration immediately following it}}
+// expected-warning@+1 {{'@function' command should be used in a comment attached to a function declaration}}
/*! @function test_function
*/
typedef unsigned int Base64Flags;
unsigned test_function(Base64Flags inFlags);
-// expected-warning@+1 {{'@callback' command used in a comment that is attached to a non-callback declaration immediately following it}}
+// expected-warning@+1 {{'@callback' command should be used in a comment attached to a pointer to function declaration}}
/*! @callback test_callback
*/
typedef unsigned int BaseFlags;
diff --git a/test/Sema/warn-documentation.m b/test/Sema/warn-documentation.m
index cfa84870e8..a0ea47ec5a 100644
--- a/test/Sema/warn-documentation.m
+++ b/test/Sema/warn-documentation.m
@@ -98,7 +98,7 @@ int b;
typedef int (^test_param1)(int aaa, int ccc);
// rdar://13094352
-// expected-warning@+2 {{'@method' command used in a comment that is attached to a non-method declaration immediately following it}}
+// expected-warning@+2 {{'@method' command should be used in a comment attached to an objective-c method declaration}}
@interface I
/*! @method Base64EncodeEx
*/