From 35ceb27fa4af18156d2cfec43dbabe0513a10cee Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 13 Aug 2012 16:37:30 +0000 Subject: [PATCH] When looking for the comment associated with a declaration, adjust the 'templated' declaration for a function or class template to refer to the function or class template itself, to which the documentation will be attached. Fixes PR13593. llvm-svn: 161762 --- clang/lib/AST/ASTContext.cpp | 11 +++++++++++ clang/test/Sema/warn-documentation.cpp | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 10cba7a813d1..1426a29f17ec 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -190,6 +190,17 @@ RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const { } const RawComment *ASTContext::getRawCommentForAnyRedecl(const Decl *D) const { + // If we have a 'templated' declaration for a template, adjust 'D' to + // refer to the actual template. + if (const FunctionDecl *FD = dyn_cast(D)) { + if (const FunctionTemplateDecl *FTD = FD->getDescribedFunctionTemplate()) + D = FTD; + } else if (const CXXRecordDecl *RD = dyn_cast(D)) { + if (const ClassTemplateDecl *CTD = RD->getDescribedClassTemplate()) + D = CTD; + } + // FIXME: Alias templates? + // Check whether we have cached a comment for this declaration already. { llvm::DenseMap::iterator Pos = diff --git a/clang/test/Sema/warn-documentation.cpp b/clang/test/Sema/warn-documentation.cpp index d116c3f8cae0..16ba4297cdc4 100644 --- a/clang/test/Sema/warn-documentation.cpp +++ b/clang/test/Sema/warn-documentation.cpp @@ -652,3 +652,19 @@ void test_nocrash1(int); /// \param\brief void test_nocrash2(int); +// PR13593 + +/** +* Bla. +*/ +template +void test_nocrash3(); + +/// Foo +template +void test_nocrash4() { } + +template +void test_nocrash3() +{ +} -- GitLab