diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h --- a/clang/include/clang/AST/Comment.h +++ b/clang/include/clang/AST/Comment.h @@ -1031,8 +1031,8 @@ ClassKind, /// Something that we consider a "variable": - /// \li namespace scope variables; - /// \li static and non-static class data members; + /// \li namespace scope variables and variable templates; + /// \li static and non-static class data members and member templates; /// \li enumerators. VariableKind, diff --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp --- a/clang/lib/AST/Comment.cpp +++ b/clang/lib/AST/Comment.cpp @@ -294,6 +294,12 @@ Kind = ClassKind; break; case Decl::Var: + if (const VarTemplateDecl *VTD = + cast(CommentDecl)->getDescribedVarTemplate()) { + TemplateKind = TemplateSpecialization; + TemplateParameters = VTD->getTemplateParameters(); + } + LLVM_FALLTHROUGH; case Decl::Field: case Decl::EnumConstant: case Decl::ObjCIvar: @@ -305,6 +311,15 @@ TSI = PD->getTypeSourceInfo(); Kind = VariableKind; break; + case Decl::VarTemplate: { + const VarTemplateDecl *VTD = cast(CommentDecl); + Kind = VariableKind; + TemplateKind = Template; + TemplateParameters = VTD->getTemplateParameters(); + if (const VarDecl *VD = VTD->getTemplatedDecl()) + TSI = VD->getTypeSourceInfo(); + break; + } case Decl::Namespace: Kind = NamespaceKind; break; diff --git a/clang/test/Sema/warn-documentation.cpp b/clang/test/Sema/warn-documentation.cpp --- a/clang/test/Sema/warn-documentation.cpp +++ b/clang/test/Sema/warn-documentation.cpp @@ -1323,6 +1323,17 @@ */ int (*functionPointerVariable)(int i); +#if __cplusplus >= 201402L +/** + * functionPointerVariableTemplate + * + * @param i is something. + * @returns integer. + */ +template +int (*functionPointerVariableTemplate)(T i); +#endif + struct HasFields { /** * functionPointerField @@ -1331,6 +1342,18 @@ * @returns integer. */ int (*functionPointerField)(int i); + +#if __cplusplus >= 201402L + /** + * functionPointerTemplateMember + * + * @tparam T some type. + * @param i is integer. + * @returns integer. + */ + template + static int (*functionPointerTemplateMember)(int i); +#endif }; // expected-warning@+5 {{parameter 'p' not found in the function declaration}} @@ -1343,6 +1366,23 @@ */ void (*functionPointerVariableThatLeadsNowhere)(); +#if __cplusplus >= 201402L +// expected-warning@+8 {{template parameter 'X' not found in the template declaration}} +// expected-note@+7 {{did you mean 'T'?}} +// expected-warning@+7 {{parameter 'p' not found in the function declaration}} +// expected-note@+6 {{did you mean 'x'?}} +// expected-warning@+6 {{'\returns' command used in a comment that is attached to a function returning void}} +/** + * functionPointerVariable + * + * \tparam X typo + * \param p not here. + * \returns integer. + */ +template +void (*functionPointerVariableTemplateThatLeadsNowhere)(T x); +#endif + // Still warn about param/returns commands for variables that don't specify // the type directly: