PATCH: Fix parameter documentation for "..." on templated functions

Joe Ranieri joe at alacatialabs.com
Tue Mar 18 12:26:41 PDT 2014


When -Wdocumentation enabled, Clang is erroneously claiming that there
is no parameter named "..." for the following code:
// \param arg An argument
/// \param ... More arguments
template<typename T>
void test_templated_function_variadic(int arg, ...);

The first attached patch fixes this. The second attached patch fixes a
failed assertion that occurs when dumping the AST of the above code.

-- Joe Ranieri
-------------- next part --------------
diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp
index 0ae0082..e51f878 100644
--- a/lib/AST/CommentSema.cpp
+++ b/lib/AST/CommentSema.cpp
@@ -792,11 +792,14 @@ bool Sema::isAnyFunctionDecl() {
 }
 
 bool Sema::isFunctionOrMethodVariadic() {
-  if (!isAnyFunctionDecl() && !isObjCMethodDecl())
+  if (!isAnyFunctionDecl() && !isObjCMethodDecl() && !isFunctionTemplateDecl())
     return false;
   if (const FunctionDecl *FD =
         dyn_cast<FunctionDecl>(ThisDeclInfo->CurrentDecl))
     return FD->isVariadic();
+  if (const FunctionTemplateDecl *FTD =
+        dyn_cast<FunctionTemplateDecl>(ThisDeclInfo->CurrentDecl))
+    return FTD->getTemplatedDecl()->isVariadic();
   if (const ObjCMethodDecl *MD =
         dyn_cast<ObjCMethodDecl>(ThisDeclInfo->CurrentDecl))
     return MD->isVariadic();
diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp
index ad7ab18..01a296b 100644
--- a/test/Sema/warn-documentation.cpp
+++ b/test/Sema/warn-documentation.cpp
@@ -1076,3 +1076,8 @@ template <class T> T test_function (T arg);
 /*!     @function test_function<int>
 */
 template <> int test_function<int> (int arg);
+
+/// \param arg An argument
+/// \param ... More arguments
+template<typename T>
+void test_templated_function_variadic(int arg, ...);
-------------- next part --------------
diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp
index eb5a7d3..54efed2 100644
--- a/lib/AST/ASTDumper.cpp
+++ b/lib/AST/ASTDumper.cpp
@@ -2069,7 +2069,7 @@ void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
       OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
   }
 
-  if (C->isParamIndexValid())
+  if (C->isParamIndexValid() && !C->isVarArgParam())
     OS << " ParamIndex=" << C->getParamIndex();
 }
 
diff --git a/test/Misc/ast-dump-comment.cpp b/test/Misc/ast-dump-comment.cpp
index 4e84af0..385d9b7 100644
--- a/test/Misc/ast-dump-comment.cpp
+++ b/test/Misc/ast-dump-comment.cpp
@@ -67,3 +67,11 @@ int Test_VerbatimBlockComment;
 // CHECK:      VarDecl{{.*}}Test_VerbatimBlockComment
 // CHECK:        VerbatimBlockComment{{.*}} Name="verbatim" CloseName="endverbatim"
 // CHECK-NEXT:     VerbatimBlockLineComment{{.*}} Text=" Aaa"
+
+/// \param ... More arguments
+template<typename T>
+void Test_TemplatedFunctionVariadic(int arg, ...);
+// CHECK:      FunctionTemplateDecl{{.*}}Test_TemplatedFunctionVariadic
+// CHECK:        ParamCommandComment{{.*}} [in] implicitly Param="..."
+// CHECK-NEXT:     ParagraphComment
+// CHECK-NEXT:     	TextComment{{.*}} Text=" More arguments"


More information about the cfe-commits mailing list