Skip to content

Commit 99d3582

Browse files
committed
Comment parsing: Specify argument numbers for some block commands
The command traits have a member NumArgs for which all the parsing infrastructure is in place, but no command was setting it to a value other than 0. By doing so we get warnings when passing an empty paragraph to \retval (the first argument is the return value, then comes the description). We also take \xrefitem along for the ride, although as the documentation states it's unlikely to be used directly. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D125422
1 parent 562ce15 commit 99d3582

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

clang/include/clang/AST/CommentCommands.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ def Post : BlockCommand<"post">;
154154
def Pre : BlockCommand<"pre">;
155155
def Remark : BlockCommand<"remark">;
156156
def Remarks : BlockCommand<"remarks">;
157-
def Retval : BlockCommand<"retval">;
157+
def Retval : BlockCommand<"retval"> { let NumArgs = 1; }
158158
def Sa : BlockCommand<"sa">;
159159
def See : BlockCommand<"see">;
160160
def Since : BlockCommand<"since">;
161161
def Test : BlockCommand<"test">;
162162
def Todo : BlockCommand<"todo">;
163163
def Version : BlockCommand<"version">;
164164
def Warning : BlockCommand<"warning">;
165-
def XRefItem : BlockCommand<"xrefitem">;
165+
def XRefItem : BlockCommand<"xrefitem"> { let NumArgs = 3; }
166166
// HeaderDoc commands
167167
def Abstract : BlockCommand<"abstract"> { let IsBriefCommand = 1; }
168168
def ClassDesign : RecordLikeDetailCommand<"classdesign">;

clang/test/AST/ast-dump-comment.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ int Test_BlockCommandComment;
3232
// CHECK-NEXT: ParagraphComment
3333
// CHECK-NEXT: TextComment{{.*}} Text=" Aaa"
3434

35+
/// \retval 42 Aaa
36+
int Test_BlockCommandComment_WithArgs();
37+
// CHECK: FunctionDecl{{.*}}Test_BlockCommandComment_WithArgs
38+
// CHECK: BlockCommandComment{{.*}} Name="retval" Arg[0]="42"
39+
// CHECK-NEXT: ParagraphComment
40+
// CHECK-NEXT: TextComment{{.*}} Text=" Aaa"
41+
3542
/// \param Aaa xxx
3643
/// \param [in,out] Bbb yyy
3744
void Test_ParamCommandComment(int Aaa, int Bbb);

clang/test/Sema/warn-documentation.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ int test_multiple_returns3(int);
189189
int test_multiple_returns4(int);
190190

191191

192+
/// expected-warning@+1 {{empty paragraph passed to '\retval' command}}
193+
/// \retval 0
194+
int test_retval_no_paragraph();
195+
196+
/// \retval 0 Everything is fine.
197+
int test_retval_fine();
198+
199+
192200
// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
193201
/// \param a Blah blah.
194202
int test_param1_backslash;

0 commit comments

Comments
 (0)