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@+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<typename T>
+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<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@+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:


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@+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<typename T>
+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<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@+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:
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to