r279754 - [Sema][Comments] Add support for TypeAliasTemplate

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 25 10:09:34 PDT 2016


Author: bruno
Date: Thu Aug 25 12:09:33 2016
New Revision: 279754

URL: http://llvm.org/viewvc/llvm-project?rev=279754&view=rev
Log:
[Sema][Comments] Add support for TypeAliasTemplate

Emit proper diagnostics when -Wdocumentation is used with constructs such as:

  template<typename T>
  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

Modified:
    cfe/trunk/lib/AST/Comment.cpp
    cfe/trunk/test/Sema/warn-documentation.cpp

Modified: cfe/trunk/lib/AST/Comment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Comment.cpp?rev=279754&r1=279753&r2=279754&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Comment.cpp (original)
+++ cfe/trunk/lib/AST/Comment.cpp Thu Aug 25 12:09:33 2016
@@ -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:

Modified: cfe/trunk/test/Sema/warn-documentation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.cpp?rev=279754&r1=279753&r2=279754&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-documentation.cpp (original)
+++ cfe/trunk/test/Sema/warn-documentation.cpp Thu Aug 25 12:09:33 2016
@@ -416,6 +416,38 @@ using test_function_like_using7 = foo::f
 /// \returns aaa.
 using test_function_like_using8 = foo::function_wrapper<int (int aaa, int ccc)> &&;
 
+// expected-warning at +4 {{template parameter 'U' not found in the template declaration}} expected-note at +4 {{did you mean 'T'?}}
+// expected-warning at +2 {{parameter 'bbb' not found in the function declaration}} expected-note at +2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \tparam U Uuu.
+template<typename T>
+using test_function_like_using9 = int(T aaa, int ccc);
+
+// expected-warning at +4 {{template parameter 'U' not found in the template declaration}} expected-note at +4 {{did you mean 'T'?}}
+// expected-warning at +2 {{parameter 'bbb' not found in the function declaration}} expected-note at +2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \tparam U Uuu.
+template<typename T>
+using test_function_like_using10 = int (*)(T aaa, int ccc);
+
+// expected-warning at +4 {{template parameter 'U' not found in the template declaration}} expected-note at +4 {{did you mean 'T'?}}
+// expected-warning at +2 {{parameter 'bbb' not found in the function declaration}} expected-note at +2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \tparam U Uuu.
+template<typename T>
+using test_function_like_using11 = foo::function_wrapper<int (T aaa, int ccc)>;
+
+// expected-warning at +4 {{template parameter 'U' not found in the template declaration}} expected-note at +4 {{did you mean 'T'?}}
+// expected-warning at +2 {{parameter 'bbb' not found in the function declaration}} expected-note at +2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \tparam U Uuu.
+template<typename T>
+using test_function_like_using12 = foo::function_wrapper<int (T aaa, int ccc)> *;
+
 using test_not_function_like_using1 = int (*)(int aaa);
 
 // expected-warning at +1 {{'\param' command used in a comment that is not attached to a function declaration}}




More information about the cfe-commits mailing list