From: Bruno Cardoso Lopes Date: Thu, 25 Aug 2016 17:09:33 +0000 (+0000) Subject: [Sema][Comments] Add support for TypeAliasTemplate X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0188dc5a04299b40481d7dd9d7c2f2123a3bad6b;p=clang [Sema][Comments] Add support for TypeAliasTemplate Emit proper diagnostics when -Wdocumentation is used with constructs such as: template using fn = int(T aaa, int ccc); Previously clang wouldn't recognize the function and complain with 'comment that is not attached to a function declaration'. Differential Revision: https://reviews.llvm.org/D23860 rdar://problem/27300695 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279754 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Comment.cpp b/lib/AST/Comment.cpp index 307104224a..7a7d3dd830 100644 --- a/lib/AST/Comment.cpp +++ b/lib/AST/Comment.cpp @@ -310,6 +310,20 @@ void DeclInfo::fill() { Kind = TypedefKind; TemplateKind = Template; TemplateParameters = TAT->getTemplateParameters(); + TypeAliasDecl *TAD = TAT->getTemplatedDecl(); + if (!TAD) + break; + + const TypeSourceInfo *TSI = TAD->getTypeSourceInfo(); + if (!TSI) + break; + TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc(); + FunctionTypeLoc FTL; + if (getFunctionTypeLoc(TL, FTL)) { + Kind = FunctionKind; + ParamVars = FTL.getParams(); + ReturnType = FTL.getReturnLoc().getType(); + } break; } case Decl::Enum: diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp index 2f2f44d632..34d8f5fd2d 100644 --- a/test/Sema/warn-documentation.cpp +++ b/test/Sema/warn-documentation.cpp @@ -416,6 +416,38 @@ using test_function_like_using7 = foo::function_wrapper /// \returns aaa. using test_function_like_using8 = foo::function_wrapper &&; +// expected-warning@+4 {{template parameter 'U' not found in the template declaration}} expected-note@+4 {{did you mean 'T'?}} +// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}} +/// \param aaa Meow. +/// \param bbb Bbb. +/// \tparam U Uuu. +template +using test_function_like_using9 = int(T aaa, int ccc); + +// expected-warning@+4 {{template parameter 'U' not found in the template declaration}} expected-note@+4 {{did you mean 'T'?}} +// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}} +/// \param aaa Meow. +/// \param bbb Bbb. +/// \tparam U Uuu. +template +using test_function_like_using10 = int (*)(T aaa, int ccc); + +// expected-warning@+4 {{template parameter 'U' not found in the template declaration}} expected-note@+4 {{did you mean 'T'?}} +// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}} +/// \param aaa Meow. +/// \param bbb Bbb. +/// \tparam U Uuu. +template +using test_function_like_using11 = foo::function_wrapper; + +// expected-warning@+4 {{template parameter 'U' not found in the template declaration}} expected-note@+4 {{did you mean 'T'?}} +// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}} +/// \param aaa Meow. +/// \param bbb Bbb. +/// \tparam U Uuu. +template +using test_function_like_using12 = foo::function_wrapper *; + using test_not_function_like_using1 = int (*)(int aaa); // expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}