[PATCH] D23860: [Sema][Comments] Add support for TypeAliasTemplate

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 24 17:33:19 PDT 2016


bruno created this revision.
bruno added a reviewer: gribozavr.
bruno added a subscriber: cfe-commits.

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'.

https://reviews.llvm.org/D23860

Files:
  lib/AST/Comment.cpp
  test/Sema/warn-documentation.cpp

Index: test/Sema/warn-documentation.cpp
===================================================================
--- test/Sema/warn-documentation.cpp
+++ test/Sema/warn-documentation.cpp
@@ -416,6 +416,22 @@
 /// \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_usingA = 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}}
Index: lib/AST/Comment.cpp
===================================================================
--- lib/AST/Comment.cpp
+++ lib/AST/Comment.cpp
@@ -310,6 +310,20 @@
     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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23860.69187.patch
Type: text/x-patch
Size: 2016 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160825/6c9eb23f/attachment.bin>


More information about the cfe-commits mailing list