aaronpuchert created this revision. aaronpuchert added reviewers: gribozavr2, Mordante. aaronpuchert requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
We treat them as variables of course, though if they have function pointer type we treat them as functions, i.e. allow parameter and return value specifications. Just like VarDecls. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D111266 Files: clang/include/clang/AST/Comment.h clang/lib/AST/Comment.cpp clang/test/Sema/warn-documentation.cpp
Index: clang/test/Sema/warn-documentation.cpp =================================================================== --- clang/test/Sema/warn-documentation.cpp +++ 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<typename T> +int (*functionPointerVariableTemplate)(T i); +#endif + struct HasFields { /** * functionPointerField @@ -1331,6 +1342,18 @@ * @returns integer. */ int (*functionPointerField)(int i); + +#if __cplusplus >= 201402L + /** + * functionPointerField + * + * @tparam T some type. + * @param i is integer. + * @returns integer. + */ + template<typename T> + 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<typename T> +void (*functionPointerVariableTemplateThatLeadsNowhere)(T x); +#endif + // Still warn about param/returns commands for variables that don't specify // the type directly: Index: clang/lib/AST/Comment.cpp =================================================================== --- clang/lib/AST/Comment.cpp +++ clang/lib/AST/Comment.cpp @@ -294,6 +294,12 @@ Kind = ClassKind; break; case Decl::Var: + if (const VarTemplateDecl *VTD = + cast<VarDecl>(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<VarTemplateDecl>(CommentDecl); + Kind = VariableKind; + TemplateKind = Template; + TemplateParameters = VTD->getTemplateParameters(); + if (const VarDecl *VD = VTD->getTemplatedDecl()) + TSI = VD->getTypeSourceInfo(); + break; + } case Decl::Namespace: Kind = NamespaceKind; break; Index: clang/include/clang/AST/Comment.h =================================================================== --- clang/include/clang/AST/Comment.h +++ clang/include/clang/AST/Comment.h @@ -1030,8 +1030,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,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits