Author: Aaron Puchert Date: 2021-11-09T22:30:09+01:00 New Revision: 63ef0e17e28827eae53133b3467bdac7d9729318
URL: https://github.com/llvm/llvm-project/commit/63ef0e17e28827eae53133b3467bdac7d9729318 DIFF: https://github.com/llvm/llvm-project/commit/63ef0e17e28827eae53133b3467bdac7d9729318.diff LOG: Comment AST: Add support for variable templates 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. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D111266 Added: Modified: clang/include/clang/AST/Comment.h clang/lib/AST/Comment.cpp clang/test/Sema/warn-documentation.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h index e394e9608426..50ed7eec8208 100644 --- a/clang/include/clang/AST/Comment.h +++ b/clang/include/clang/AST/Comment.h @@ -1031,8 +1031,8 @@ struct DeclInfo { 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 index ce90abf55294..5e6a7de5b563 100644 --- a/clang/lib/AST/Comment.cpp +++ b/clang/lib/AST/Comment.cpp @@ -294,6 +294,12 @@ void DeclInfo::fill() { 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 @@ void DeclInfo::fill() { 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; diff --git a/clang/test/Sema/warn-documentation.cpp b/clang/test/Sema/warn-documentation.cpp index f30f05fccd71..3a25c31f76f5 100644 --- a/clang/test/Sema/warn-documentation.cpp +++ b/clang/test/Sema/warn-documentation.cpp @@ -1323,6 +1323,17 @@ namespace AllowParamAndReturnsOnFunctionPointerVars { */ 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 @@ struct HasFields { * @returns integer. */ int (*functionPointerField)(int i); + +#if __cplusplus >= 201402L + /** + * functionPointerTemplateMember + * + * @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 @@ struct HasFields { */ 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: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits