From: Dmitri Gribenko Date: Sun, 27 Jan 2013 21:18:39 +0000 (+0000) Subject: Comment parsing: attach any tag type's documentation to its typedef if latter X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d1e5c0df2acb01192eedda14534fe990e1e26c46;p=clang Comment parsing: attach any tag type's documentation to its typedef if latter does not have one of its own. // rdar://13067629 Original patch (r173586 and r173587) by Fariborz Jahanian, modified by me. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173626 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 7ba64e32f3..8091d685f7 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -85,6 +85,14 @@ RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const { return NULL; } + if (const ClassTemplateSpecializationDecl *CTSD = + dyn_cast(D)) { + TemplateSpecializationKind TSK = CTSD->getSpecializationKind(); + if (TSK == TSK_ImplicitInstantiation || + TSK == TSK_Undeclared) + return NULL; + } + if (const EnumDecl *ED = dyn_cast(D)) { if (ED->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) return NULL; @@ -428,12 +436,12 @@ comments::FullComment *ASTContext::getCommentForDecl( return cloneFullComment(FC, D); } else if (const TypedefDecl *TD = dyn_cast(D)) { - // Attach enum's documentation to its typedef if latter + // Attach any tag type's documentation to its typedef if latter // does not have one of its own. QualType QT = TD->getUnderlyingType(); - if (const EnumType *ET = QT->getAs()) - if (const EnumDecl *ED = ET->getDecl()) - if (comments::FullComment *FC = getCommentForDecl(ED, PP)) + if (const TagType *TT = QT->getAs()) + if (const Decl *TD = TT->getDecl()) + if (comments::FullComment *FC = getCommentForDecl(TD, PP)) return cloneFullComment(FC, D); } return NULL; diff --git a/test/Index/annotate-comments-typedef.m b/test/Index/annotate-comments-typedef.m index 6e5fb73520..4c2b62b2c9 100644 --- a/test/Index/annotate-comments-typedef.m +++ b/test/Index/annotate-comments-typedef.m @@ -27,4 +27,23 @@ enum E { E_MyEnumBaz, /**< value Baz */ }; typedef enum E E_T; -// CHECK: TypedefDecl=E_T:[[@LINE-1]]:16 (Definition) FullCommentAsHTML=[

Documentation for E

] FullCommentAsXML=[Ec:@E@Etypedef enum E E_T Documentation for E ] +// CHECK: EnumDecl=E:[[@LINE-6]]:6 (Definition) {{.*}} BriefComment=[Documentation for E] FullCommentAsHTML=[

Documentation for E

] FullCommentAsXML=[Ec:@E@Eenum E {} Documentation for E ] +// CHECK: TypedefDecl=E_T:[[@LINE-2]]:16 (Definition) FullCommentAsHTML=[

Documentation for E

] FullCommentAsXML=[Ec:@E@Etypedef enum E E_T Documentation for E ] + + +/** Comment about Foo */ +typedef struct { + int iii; + } Foo; +// CHECK: TypedefDecl=Foo:[[@LINE-1]]:11 (Definition) FullCommentAsHTML=[

Comment about Foo

] FullCommentAsXML=[<anonymous>c:@SA@Footypedef struct Foo Foo Comment about Foo ] +// CHECK: StructDecl=:[[@LINE-4]]:9 (Definition) {{.*}} BriefComment=[Comment about Foo] FullCommentAsHTML=[

Comment about Foo

] FullCommentAsXML=[<anonymous>c:@SA@Foostruct {} Comment about Foo ] + + +struct Foo1 { + int iii; +}; +/** About Foo1T */ +typedef struct Foo1 Foo1T; +// FIXME: we don't attach this comment to 'struct Foo1' +// CHECK: TypedefDecl=Foo1T:[[@LINE-2]]:21 (Definition) {{.*}} FullCommentAsHTML=[

About Foo1T

] FullCommentAsXML=[Foo1Tc:annotate-comments-typedef.m@{{[0-9]+}}@T@Foo1Ttypedef struct Foo1 Foo1T About Foo1T ] + diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp index 6a6b8dd599..9845f58780 100644 --- a/test/Sema/warn-documentation.cpp +++ b/test/Sema/warn-documentation.cpp @@ -377,6 +377,29 @@ using test_tparam14 = test_tparam13; template using test_tparam15 = test_tparam13; +// ---- + +/// \tparam T Aaa +template +class test_tparam16 { }; + +typedef test_tparam16 test_tparam17; +typedef test_tparam16 test_tparam18; + +// ---- + +template +class test_tparam19; + +typedef test_tparam19 test_tparam20; +typedef test_tparam19 test_tparam21; + +/// \tparam T Aaa +template +class test_tparam19 { }; + +// ---- + /// Aaa /// \deprecated Bbb