Skip to content

Commit b09db22

Browse files
committed
[Sema][Comments] Support @param with c++ 'using' keyword
Give appropriate warnings with -Wdocumentation for @param comments that refer to function aliases defined with 'using'. Very similar to typedef's behavior. This does not add support for TypeAliasTemplateDecl yet. Differential Revision: https://reviews.llvm.org/D23783 rdar://problem/27300695 llvm-svn: 279662
1 parent 6d03d84 commit b09db22

File tree

2 files changed

+69
-6
lines changed

2 files changed

+69
-6
lines changed

clang/lib/AST/Comment.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,15 @@ void DeclInfo::fill() {
226226
case Decl::Namespace:
227227
Kind = NamespaceKind;
228228
break;
229+
case Decl::TypeAlias:
229230
case Decl::Typedef: {
230231
Kind = TypedefKind;
231-
// If this is a typedef to something we consider a function, extract
232+
// If this is a typedef / using to something we consider a function, extract
232233
// arguments and return type.
233-
const TypedefDecl *TD = cast<TypedefDecl>(CommentDecl);
234-
const TypeSourceInfo *TSI = TD->getTypeSourceInfo();
234+
const TypeSourceInfo *TSI =
235+
K == Decl::Typedef
236+
? cast<TypedefDecl>(CommentDecl)->getTypeSourceInfo()
237+
: cast<TypeAliasDecl>(CommentDecl)->getTypeSourceInfo();
235238
if (!TSI)
236239
break;
237240
TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
@@ -302,9 +305,6 @@ void DeclInfo::fill() {
302305
}
303306
break;
304307
}
305-
case Decl::TypeAlias:
306-
Kind = TypedefKind;
307-
break;
308308
case Decl::TypeAliasTemplate: {
309309
const TypeAliasTemplateDecl *TAT = cast<TypeAliasTemplateDecl>(CommentDecl);
310310
Kind = TypedefKind;

clang/test/Sema/warn-documentation.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,69 @@ typedef unsigned int test_not_function_like_typedef3;
368368
/// \param aaa Meow.
369369
typedef foo::not_a_function_wrapper<1> test_not_function_like_typedef4;
370370

371+
// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
372+
/// \param aaa Meow.
373+
/// \param bbb Bbb.
374+
/// \returns aaa.
375+
using test_function_like_using1 = int (int aaa, int ccc);
376+
377+
// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
378+
/// \param aaa Meow.
379+
/// \param bbb Bbb.
380+
/// \returns aaa.
381+
using test_function_like_using2 = int (*)(int aaa, int ccc);
382+
383+
// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
384+
/// \param aaa Meow.
385+
/// \param bbb Bbb.
386+
/// \returns aaa.
387+
using test_function_like_using3 = int (* const)(int aaa, int ccc);
388+
389+
// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
390+
/// \param aaa Meow.
391+
/// \param bbb Bbb.
392+
/// \returns aaa.
393+
using test_function_like_using4 = int (C::*)(int aaa, int ccc);
394+
395+
// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
396+
/// \param aaa Meow.
397+
/// \param bbb Bbb.
398+
/// \returns aaa.
399+
using test_function_like_using5 = foo::function_wrapper<int (int aaa, int ccc)>;
400+
401+
// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
402+
/// \param aaa Meow.
403+
/// \param bbb Bbb.
404+
/// \returns aaa.
405+
using test_function_like_using6 = foo::function_wrapper<int (int aaa, int ccc)> *;
406+
407+
// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
408+
/// \param aaa Meow.
409+
/// \param bbb Bbb.
410+
/// \returns aaa.
411+
using test_function_like_using7 = foo::function_wrapper<int (int aaa, int ccc)> &;
412+
413+
// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
414+
/// \param aaa Meow.
415+
/// \param bbb Bbb.
416+
/// \returns aaa.
417+
using test_function_like_using8 = foo::function_wrapper<int (int aaa, int ccc)> &&;
418+
419+
using test_not_function_like_using1 = int (*)(int aaa);
420+
421+
// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
422+
/// \param aaa Meow.
423+
using test_not_function_like_using2 = test_not_function_like_using1;
424+
425+
// Check that the diagnostic uses the same command marker as the comment.
426+
// expected-warning@+1 {{'@param' command used in a comment that is not attached to a function declaration}}
427+
/// @param aaa Meow.
428+
using test_not_function_like_using3 = unsigned int;
429+
430+
// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
431+
/// \param aaa Meow.
432+
using test_not_function_like_using4 = foo::not_a_function_wrapper<1>;
433+
371434
/// \param aaa Aaa
372435
/// \param ... Vararg
373436
int test_vararg_param1(int aaa, ...);

0 commit comments

Comments
 (0)