From 2d588b4bc7127adf1a1c621002dfe452a99fef6f Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 19 Jun 2013 18:08:03 +0000 Subject: [PATCH] documentation parsing: patch to make @class work for class templates; and similarly, @function works for function templates. // rdar://14124702 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184329 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/CommentSema.h | 2 ++ lib/AST/CommentSema.cpp | 24 ++++++++++++++--- test/Sema/warn-documentation.cpp | 44 ++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/include/clang/AST/CommentSema.h b/include/clang/AST/CommentSema.h index 15e454dcc3..753cae3e81 100644 --- a/include/clang/AST/CommentSema.h +++ b/include/clang/AST/CommentSema.h @@ -220,6 +220,8 @@ public: bool isUnionDecl(); bool isObjCInterfaceDecl(); bool isObjCProtocolDecl(); + bool isClassTemplateDecl(); + bool isFunctionTemplateDecl(); ArrayRef getParamVars(); diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp index c242eb0f60..06f23462ef 100644 --- a/lib/AST/CommentSema.cpp +++ b/lib/AST/CommentSema.cpp @@ -99,10 +99,10 @@ void Sema::checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment) { unsigned DiagSelect; switch (Comment->getCommandID()) { case CommandTraits::KCI_function: - DiagSelect = !isAnyFunctionDecl() ? 1 : 0; + DiagSelect = (!isAnyFunctionDecl() && !isFunctionTemplateDecl())? 1 : 0; break; case CommandTraits::KCI_functiongroup: - DiagSelect = !isAnyFunctionDecl() ? 2 : 0; + DiagSelect = (!isAnyFunctionDecl() && !isFunctionTemplateDecl())? 2 : 0; break; case CommandTraits::KCI_method: DiagSelect = !isObjCMethodDecl() ? 3 : 0; @@ -131,7 +131,7 @@ void Sema::checkContainerDeclVerbatimLine(const BlockCommandComment *Comment) { unsigned DiagSelect; switch (Comment->getCommandID()) { case CommandTraits::KCI_class: - DiagSelect = !isClassOrStructDecl() ? 1 : 0; + DiagSelect = (!isClassOrStructDecl() && !isClassTemplateDecl()) ? 1 : 0; // Allow @class command on @interface declarations. // FIXME. Currently, \class and @class are indistinguishable. So, // \class is also allowed on an @interface declaration @@ -870,6 +870,24 @@ bool Sema::isClassOrStructDecl() { isa(ThisDeclInfo->CurrentDecl) && !isUnionDecl(); } + +bool Sema::isClassTemplateDecl() { + if (!ThisDeclInfo) + return false; + if (!ThisDeclInfo->IsFilled) + inspectThisDecl(); + return ThisDeclInfo->CurrentDecl && + (isa(ThisDeclInfo->CurrentDecl)); +} + +bool Sema::isFunctionTemplateDecl() { + if (!ThisDeclInfo) + return false; + if (!ThisDeclInfo->IsFilled) + inspectThisDecl(); + return ThisDeclInfo->CurrentDecl && + (isa(ThisDeclInfo->CurrentDecl)); +} bool Sema::isObjCInterfaceDecl() { if (!ThisDeclInfo) diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp index b3ab0199dc..1306ac991f 100644 --- a/test/Sema/warn-documentation.cpp +++ b/test/Sema/warn-documentation.cpp @@ -950,3 +950,47 @@ class C1; @struct S3; */ class S3; + +// rdar://14124702 +//---------------------------------------------------------------------- +/// @class Predicate Predicate.h "lldb/Host/Predicate.h" +/// @brief A C++ wrapper class for providing threaded access to a value +/// of type T. +/// +/// A templatized class. +/// specified values. +//---------------------------------------------------------------------- +template +class Predicate +{ +}; + +//---------------------------------------------------------------------- +/// @class Predicate Predicate.h "lldb/Host/Predicate.h" +/// @brief A C++ wrapper class for providing threaded access to a value +/// of type T. +/// +/// A template specilization class. +//---------------------------------------------------------------------- +template<> class Predicate +{ +}; + +//---------------------------------------------------------------------- +/// @class Predicate Predicate.h "lldb/Host/Predicate.h" +/// @brief A C++ wrapper class for providing threaded access to a value +/// of type T. +/// +/// A partial specialization template class. +//---------------------------------------------------------------------- +template class Predicate +{ +}; + +/*! @function test_function +*/ +template T test_function (T arg); + +/*! @function test_function +*/ +template <> int test_function (int arg); -- 2.40.0