Clang Project

clang_source_code/test/Sema/warn-documentation.cpp
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic -verify %s
2
3// This file contains lots of corner cases, so ensure that XML we generate is not invalid.
4// RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng %s | FileCheck %s -check-prefix=WRONG
5// WRONG-NOT: CommentXMLInvalid
6
7// expected-warning@+2 {{HTML tag 'a' requires an end tag}}
8// expected-warning@+1 {{expected quoted string after equals sign}}
9/// <a href=>
10int test_html1(int);
11
12// expected-warning@+2 {{HTML tag 'a' requires an end tag}}
13// expected-warning@+1 {{expected quoted string after equals sign}}
14/// <a href==>
15int test_html2(int);
16
17// expected-warning@+3 {{HTML tag 'a' requires an end tag}}
18// expected-warning@+2 {{expected quoted string after equals sign}}
19// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
20/// <a href= blah
21int test_html3(int);
22
23// expected-warning@+2 {{HTML tag 'a' requires an end tag}}
24// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
25/// <a =>
26int test_html4(int);
27
28// expected-warning@+2 {{HTML tag 'a' requires an end tag}}
29// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
30/// <a "aaa">
31int test_html5(int);
32
33// expected-warning@+2 {{HTML tag 'a' requires an end tag}}
34// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
35/// <a a="b" =>
36int test_html6(int);
37
38// expected-warning@+2 {{HTML tag 'a' requires an end tag}}
39// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
40/// <a a="b" "aaa">
41int test_html7(int);
42
43// expected-warning@+2 {{HTML tag 'a' requires an end tag}}
44// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
45/// <a a="b" =
46int test_html8(int);
47
48// expected-warning@+2 {{HTML start tag prematurely ended, expected attribute name or '>'}} expected-note@+1 {{HTML tag started here}}
49/** Aaa bbb<img ddd eee
50 * fff ggg.
51 */
52int test_html9(int);
53
54// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
55/** Aaa bbb<img ddd eee 42%
56 * fff ggg.
57 */
58int test_html10(int);
59
60// expected-warning@+1 {{HTML end tag 'br' is forbidden}}
61/// <br></br>
62int test_html11(int);
63
64/// <blockquote>Meow</blockquote>
65int test_html_nesting1(int);
66
67/// <b><i>Meow</i></b>
68int test_html_nesting2(int);
69
70/// <p>Aaa<br>
71/// Bbb</p>
72int test_html_nesting3(int);
73
74/// <p>Aaa<br />
75/// Bbb</p>
76int test_html_nesting4(int);
77
78// expected-warning@+3 {{HTML tag 'b' requires an end tag}}
79// expected-warning@+2 {{HTML tag 'i' requires an end tag}}
80// expected-warning@+1 {{HTML end tag does not match any start tag}}
81/// <b><i>Meow</a>
82int test_html_nesting5(int);
83
84// expected-warning@+2 {{HTML start tag 'i' closed by 'b'}}
85// expected-warning@+1 {{HTML end tag does not match any start tag}}
86/// <b><i>Meow</b></b>
87int test_html_nesting6(int);
88
89// expected-warning@+2 {{HTML start tag 'i' closed by 'b'}}
90// expected-warning@+1 {{HTML end tag does not match any start tag}}
91/// <b><i>Meow</b></i>
92int test_html_nesting7(int);
93
94// expected-warning@+1 {{HTML tag 'b' requires an end tag}}
95/// <b>Meow
96int test_html_nesting8(int);
97
98// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
99/// \brief\returns Aaa
100int test_block_command1(int);
101
102// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
103/// \brief \returns Aaa
104int test_block_command2(int);
105
106// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
107/// \brief
108/// \returns Aaa
109int test_block_command3(int);
110
111// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
112/// \brief
113///
114/// \returns Aaa
115int test_block_command4(int);
116
117// There is trailing whitespace on one of the following lines, don't remove it!
118// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
119/// \brief
120/// 
121/// \returns Aaa
122int test_block_command5(int);
123
124/// \brief \c Aaa
125int test_block_command6(int);
126
127// expected-warning@+5 {{duplicated command '\brief'}} expected-note@+1 {{previous command '\brief' here}}
128/// \brief Aaa
129///
130/// Bbb
131///
132/// \brief Ccc
133int test_duplicate_brief1(int);
134
135// expected-warning@+5 {{duplicated command '\short'}} expected-note@+1 {{previous command '\short' here}}
136/// \short Aaa
137///
138/// Bbb
139///
140/// \short Ccc
141int test_duplicate_brief2(int);
142
143// expected-warning@+5 {{duplicated command '\brief'}} expected-note@+1 {{previous command '\short' (an alias of '\brief') here}}
144/// \short Aaa
145///
146/// Bbb
147///
148/// \brief Ccc
149int test_duplicate_brief3(int);
150
151
152/// \return Aaa
153///
154/// Bbb
155///
156/// \return Ccc
157int test_multiple_returns1(int);
158
159/// \returns Aaa
160///
161/// Bbb
162///
163/// \returns Ccc
164int test_multiple_returns2(int);
165
166/// \result Aaa
167///
168/// Bbb
169///
170/// \result Ccc
171int test_multiple_returns3(int);
172
173/// \returns Aaa
174///
175/// Bbb
176///
177/// \return Ccc
178int test_multiple_returns4(int);
179
180
181// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
182/// \param a Blah blah.
183int test_param1_backslash;
184
185// rdar://13066276
186// Check that the diagnostic uses the same command marker as the comment.
187// expected-warning@+1 {{'@param' command used in a comment that is not attached to a function declaration}}
188/// @param a Blah blah.
189int test_param1_at;
190
191// expected-warning@+1 {{empty paragraph passed to '\param' command}}
192/// \param
193/// \param a Blah blah.
194int test_param2(int a);
195
196// expected-warning@+1 {{empty paragraph passed to '\param' command}}
197/// \param a
198int test_param3(int a);
199
200/// \param a Blah blah.
201int test_param4(int a);
202
203/// \param [in] a Blah blah.
204int test_param5(int a);
205
206/// \param [out] a Blah blah.
207int test_param6(int a);
208
209/// \param [in,out] a Blah blah.
210int test_param7(int a);
211
212// expected-warning@+1 {{whitespace is not allowed in parameter passing direction}}
213/// \param [ in ] a Blah blah.
214int test_param8(int a);
215
216// expected-warning@+1 {{whitespace is not allowed in parameter passing direction}}
217/// \param [in, out] a Blah blah.
218int test_param9(int a);
219
220// expected-warning@+1 {{unrecognized parameter passing direction, valid directions are '[in]', '[out]' and '[in,out]'}}
221/// \param [ junk] a Blah blah.
222int test_param10(int a);
223
224// expected-warning@+1 {{parameter 'a' not found in the function declaration}}
225/// \param a Blah blah.
226int test_param11();
227
228// expected-warning@+1 {{parameter 'A' not found in the function declaration}} expected-note@+1 {{did you mean 'a'?}}
229/// \param A Blah blah.
230int test_param12(int a);
231
232// expected-warning@+1 {{parameter 'aab' not found in the function declaration}} expected-note@+1 {{did you mean 'aaa'?}}
233/// \param aab Blah blah.
234int test_param13(int aaa, int bbb);
235
236// expected-warning@+2 {{parameter 'aab' not found in the function declaration}} expected-note@+2 {{did you mean 'bbb'?}}
237/// \param aaa Blah blah.
238/// \param aab Blah blah.
239int test_param14(int aaa, int bbb);
240
241// expected-warning@+1 {{parameter 'aab' not found in the function declaration}}
242/// \param aab Blah blah.
243int test_param15(int bbb, int ccc);
244
245// expected-warning@+1 {{parameter 'aab' not found in the function declaration}}
246/// \param aab Ccc.
247/// \param aaa Aaa.
248/// \param bbb Bbb.
249int test_param16(int aaa, int bbb);
250
251// expected-warning@+2 {{parameter 'aab' not found in the function declaration}}
252/// \param aaa Aaa.
253/// \param aab Ccc.
254/// \param bbb Bbb.
255int test_param17(int aaa, int bbb);
256
257// expected-warning@+3 {{parameter 'aab' not found in the function declaration}}
258/// \param aaa Aaa.
259/// \param bbb Bbb.
260/// \param aab Ccc.
261int test_param18(int aaa, int bbb);
262
263class C {
264  // expected-warning@+1 {{parameter 'aaa' not found in the function declaration}}
265  /// \param aaa Blah blah.
266  C(int bbb, int ccc);
267
268  // expected-warning@+1 {{parameter 'aaa' not found in the function declaration}}
269  /// \param aaa Blah blah.
270 int test_param19(int bbb, int ccc);
271};
272
273// expected-warning@+1 {{parameter 'aab' not found in the function declaration}}
274/// \param aab Blah blah.
275template<typename T>
276void test_param20(int bbb, int ccc);
277
278// expected-warning@+3 {{parameter 'a' is already documented}}
279// expected-note@+1 {{previous documentation}}
280/// \param a Aaa.
281/// \param a Aaa.
282int test_param21(int a);
283
284// expected-warning@+4 {{parameter 'x2' is already documented}}
285// expected-note@+2 {{previous documentation}}
286/// \param x1 Aaa.
287/// \param x2 Bbb.
288/// \param x2 Ccc.
289int test_param22(int x1, int x2, int x3);
290
291//===---
292// Test that we treat typedefs to some non-function types as functions for the
293// purposes of documentation comment parsing.
294//===---
295
296namespace foo {
297  inline namespace bar {
298    template<typename>
299    struct function_wrapper {};
300
301    template<unsigned>
302    struct not_a_function_wrapper {};
303  }
304};
305
306// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
307/// \param aaa Meow.
308/// \param bbb Bbb.
309/// \returns aaa.
310typedef int test_function_like_typedef1(int aaa, int ccc);
311
312// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
313/// \param aaa Meow.
314/// \param bbb Bbb.
315/// \returns aaa.
316typedef int (*test_function_like_typedef2)(int aaa, int ccc);
317
318// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
319/// \param aaa Meow.
320/// \param bbb Bbb.
321/// \returns aaa.
322typedef int (* const test_function_like_typedef3)(int aaa, int ccc);
323
324// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
325/// \param aaa Meow.
326/// \param bbb Bbb.
327/// \returns aaa.
328typedef int (C::*test_function_like_typedef4)(int aaa, int ccc);
329
330// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
331/// \param aaa Meow.
332/// \param bbb Bbb.
333/// \returns aaa.
334typedef foo::function_wrapper<int (int aaa, int ccc)> test_function_like_typedef5;
335
336// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
337/// \param aaa Meow.
338/// \param bbb Bbb.
339/// \returns aaa.
340typedef foo::function_wrapper<int (int aaa, int ccc)> *test_function_like_typedef6;
341
342// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
343/// \param aaa Meow.
344/// \param bbb Bbb.
345/// \returns aaa.
346typedef foo::function_wrapper<int (int aaa, int ccc)> &test_function_like_typedef7;
347
348// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
349/// \param aaa Meow.
350/// \param bbb Bbb.
351/// \returns aaa.
352typedef foo::function_wrapper<int (int aaa, int ccc)> &&test_function_like_typedef8;
353
354
355typedef int (*test_not_function_like_typedef1)(int aaa);
356
357// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
358/// \param aaa Meow.
359typedef test_not_function_like_typedef1 test_not_function_like_typedef2;
360
361// rdar://13066276
362// Check that the diagnostic uses the same command marker as the comment.
363// expected-warning@+1 {{'@param' command used in a comment that is not attached to a function declaration}}
364/// @param aaa Meow.
365typedef unsigned int test_not_function_like_typedef3;
366
367// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
368/// \param aaa Meow.
369typedef foo::not_a_function_wrapper<1> test_not_function_like_typedef4;
370
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.
375using 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.
381using 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.
387using 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.
393using 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.
399using 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.
405using 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.
411using 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.
417using test_function_like_using8 = foo::function_wrapper<int (int aaa, int ccc)> &&;
418
419// expected-warning@+4 {{template parameter 'U' not found in the template declaration}} expected-note@+4 {{did you mean 'T'?}}
420// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
421/// \param aaa Meow.
422/// \param bbb Bbb.
423/// \tparam U Uuu.
424template<typename T>
425using test_function_like_using9 = int(T aaa, int ccc);
426
427// expected-warning@+4 {{template parameter 'U' not found in the template declaration}} expected-note@+4 {{did you mean 'T'?}}
428// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
429/// \param aaa Meow.
430/// \param bbb Bbb.
431/// \tparam U Uuu.
432template<typename T>
433using test_function_like_using10 = int (*)(T aaa, int ccc);
434
435// expected-warning@+4 {{template parameter 'U' not found in the template declaration}} expected-note@+4 {{did you mean 'T'?}}
436// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
437/// \param aaa Meow.
438/// \param bbb Bbb.
439/// \tparam U Uuu.
440template<typename T>
441using test_function_like_using11 = foo::function_wrapper<int (T aaa, int ccc)>;
442
443// expected-warning@+4 {{template parameter 'U' not found in the template declaration}} expected-note@+4 {{did you mean 'T'?}}
444// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
445/// \param aaa Meow.
446/// \param bbb Bbb.
447/// \tparam U Uuu.
448template<typename T>
449using test_function_like_using12 = foo::function_wrapper<int (T aaa, int ccc)> *;
450
451using test_not_function_like_using1 = int (*)(int aaa);
452
453// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
454/// \param aaa Meow.
455using test_not_function_like_using2 = test_not_function_like_using1;
456
457// Check that the diagnostic uses the same command marker as the comment.
458// expected-warning@+1 {{'@param' command used in a comment that is not attached to a function declaration}}
459/// @param aaa Meow.
460using test_not_function_like_using3 = unsigned int;
461
462// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
463/// \param aaa Meow.
464using test_not_function_like_using4 = foo::not_a_function_wrapper<1>;
465
466/// \param aaa Aaa
467/// \param ... Vararg
468int test_vararg_param1(int aaa, ...);
469
470/// \param ... Vararg
471int test_vararg_param2(...);
472
473// expected-warning@+1 {{parameter '...' not found in the function declaration}} expected-note@+1 {{did you mean 'aaa'?}}
474/// \param ... Vararg
475int test_vararg_param3(int aaa);
476
477// expected-warning@+1 {{parameter '...' not found in the function declaration}}
478/// \param ... Vararg
479int test_vararg_param4();
480
481
482/// \param aaa Aaa
483/// \param ... Vararg
484template<typename T>
485int test_template_vararg_param1(int aaa, ...);
486
487/// \param ... Vararg
488template<typename T>
489int test_template_vararg_param2(...);
490
491// expected-warning@+1 {{parameter '...' not found in the function declaration}} expected-note@+1 {{did you mean 'aaa'?}}
492/// \param ... Vararg
493template<typename T>
494int test_template_vararg_param3(int aaa);
495
496// expected-warning@+1 {{parameter '...' not found in the function declaration}}
497/// \param ... Vararg
498template<typename T>
499int test_template_vararg_param4();
500
501
502// expected-warning@+1 {{'\tparam' command used in a comment that is not attached to a template declaration}}
503/// \tparam T Aaa
504int test_tparam1;
505
506// expected-warning@+1 {{'\tparam' command used in a comment that is not attached to a template declaration}}
507/// \tparam T Aaa
508void test_tparam2(int aaa);
509
510// expected-warning@+1 {{empty paragraph passed to '\tparam' command}}
511/// \tparam
512/// \param aaa Blah blah
513template<typename T>
514void test_tparam3(T aaa);
515
516// expected-warning@+1 {{template parameter 'T' not found in the template declaration}} expected-note@+1 {{did you mean 'TT'?}}
517/// \tparam T Aaa
518template<typename TT>
519void test_tparam4(TT aaa);
520
521// expected-warning@+1 {{template parameter 'T' not found in the template declaration}} expected-note@+1 {{did you mean 'TT'?}}
522/// \tparam T Aaa
523template<typename TT>
524class test_tparam5 {
525  // expected-warning@+1 {{template parameter 'T' not found in the template declaration}} expected-note@+1 {{did you mean 'TTT'?}}
526  /// \tparam T Aaa
527  template<typename TTT>
528  void test_tparam6(TTT aaa);
529};
530
531/// \tparam T1 Aaa
532/// \tparam T2 Bbb
533template<typename T1, typename T2>
534void test_tparam7(T1 aaa, T2 bbb);
535
536// expected-warning@+1 {{template parameter 'SomTy' not found in the template declaration}} expected-note@+1 {{did you mean 'SomeTy'?}}
537/// \tparam SomTy Aaa
538/// \tparam OtherTy Bbb
539template<typename SomeTy, typename OtherTy>
540void test_tparam8(SomeTy aaa, OtherTy bbb);
541
542// expected-warning@+2 {{template parameter 'T1' is already documented}} expected-note@+1 {{previous documentation}}
543/// \tparam T1 Aaa
544/// \tparam T1 Bbb
545template<typename T1, typename T2>
546void test_tparam9(T1 aaa, T2 bbb);
547
548/// \tparam T Aaa
549/// \tparam TT Bbb
550template<template<typename T> class TT>
551void test_tparam10(TT<int> aaa);
552
553/// \tparam T Aaa
554/// \tparam TT Bbb
555/// \tparam TTT Ccc
556template<template<template<typename T> class TT, class C> class TTT>
557void test_tparam11();
558
559/// \tparam I Aaa
560template<int I>
561void test_tparam12();
562
563template<typename T, typename U>
564class test_tparam13 { };
565
566/// \tparam T Aaa
567template<typename T>
568using test_tparam14 = test_tparam13<T, int>;
569
570// expected-warning@+1 {{template parameter 'U' not found in the template declaration}} expected-note@+1 {{did you mean 'T'?}}
571/// \tparam U Aaa
572template<typename T>
573using test_tparam15 = test_tparam13<T, int>;
574
575// ----
576
577/// \tparam T Aaa
578template<typename T>
579class test_tparam16 { };
580
581typedef test_tparam16<int> test_tparam17;
582typedef test_tparam16<double> test_tparam18;
583
584// ----
585
586template<typename T>
587class test_tparam19;
588
589typedef test_tparam19<int> test_tparam20;
590typedef test_tparam19<double> test_tparam21;
591
592/// \tparam T Aaa
593template<typename T>
594class test_tparam19 { };
595
596// ----
597
598// expected-warning@+1 {{'@tparam' command used in a comment that is not attached to a template declaration}}
599/// @tparam T Aaa
600int test_tparam22;
601
602// ----
603
604
605/// Aaa
606/// \deprecated Bbb
607void test_deprecated_1(int a) __attribute__((deprecated));
608
609// We don't want \deprecated to warn about empty paragraph.  It is fine to use
610// \deprecated by itself without explanations.
611
612/// Aaa
613/// \deprecated
614void test_deprecated_2(int a) __attribute__((deprecated));
615
616/// Aaa
617/// \deprecated
618void test_deprecated_3(int a) __attribute__((availability(macosx,introduced=10.4)));
619
620/// Aaa
621/// \deprecated
622void test_deprecated_4(int a) __attribute__((unavailable));
623
624// expected-warning@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}} expected-note@+3 {{add a deprecation attribute to the declaration to silence this warning}}
625/// Aaa
626/// \deprecated
627void test_deprecated_5(int a);
628
629// expected-warning@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}} expected-note@+3 {{add a deprecation attribute to the declaration to silence this warning}}
630/// Aaa
631/// \deprecated
632void test_deprecated_6(int a) {
633}
634
635// expected-warning@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
636/// Aaa
637/// \deprecated
638template<typename T>
639void test_deprecated_7(T aaa);
640
641
642// rdar://12397511
643// expected-note@+2 {{previous command '\headerfile' here}}
644// expected-warning@+2 {{duplicated command '\headerfile'}}
645/// \headerfile ""
646/// \headerfile foo.h
647int test__headerfile_1(int a);
648
649
650/// \invariant aaa
651void test_invariant_1(int a);
652
653// expected-warning@+1 {{empty paragraph passed to '\invariant' command}}
654/// \invariant
655void test_invariant_2(int a);
656
657
658// no-warning
659/// \returns Aaa
660int test_returns_right_decl_1(int);
661
662class test_returns_right_decl_2 {
663  // no-warning
664  /// \returns Aaa
665  int test_returns_right_decl_3(int);
666};
667
668// no-warning
669/// \returns Aaa
670template<typename T>
671int test_returns_right_decl_4(T aaa);
672
673// no-warning
674/// \returns Aaa
675template<>
676int test_returns_right_decl_4(int aaa);
677
678/// \returns Aaa
679template<typename T>
680T test_returns_right_decl_5(T aaa);
681
682// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
683/// \returns Aaa
684int test_returns_wrong_decl_1_backslash;
685
686// rdar://13066276
687// Check that the diagnostic uses the same command marker as the comment.
688// expected-warning@+1 {{'@returns' command used in a comment that is not attached to a function or method declaration}}
689/// @returns Aaa
690int test_returns_wrong_decl_1_at;
691
692// expected-warning@+1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
693/// \return Aaa
694int test_returns_wrong_decl_2;
695
696// expected-warning@+1 {{'\result' command used in a comment that is not attached to a function or method declaration}}
697/// \result Aaa
698int test_returns_wrong_decl_3;
699
700// expected-warning@+1 {{'\returns' command used in a comment that is attached to a function returning void}}
701/// \returns Aaa
702void test_returns_wrong_decl_4(int);
703
704// expected-warning@+1 {{'\returns' command used in a comment that is attached to a function returning void}}
705/// \returns Aaa
706template<typename T>
707void test_returns_wrong_decl_5(T aaa);
708
709// expected-warning@+1 {{'\returns' command used in a comment that is attached to a function returning void}}
710/// \returns Aaa
711template<>
712void test_returns_wrong_decl_5(int aaa);
713
714// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
715/// \returns Aaa
716struct test_returns_wrong_decl_6 { };
717
718// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
719/// \returns Aaa
720class test_returns_wrong_decl_7 {
721  // expected-warning@+1 {{'\returns' command used in a comment that is attached to a constructor}}
722  /// \returns Aaa
723  test_returns_wrong_decl_7();
724
725  // expected-warning@+1 {{'\returns' command used in a comment that is attached to a destructor}}
726  /// \returns Aaa
727  ~test_returns_wrong_decl_7();
728};
729
730// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
731/// \returns Aaa
732enum test_returns_wrong_decl_8 {
733  // expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
734  /// \returns Aaa
735  test_returns_wrong_decl_9
736};
737
738// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
739/// \returns Aaa
740namespace test_returns_wrong_decl_10 { };
741
742// rdar://13094352
743// expected-warning@+1 {{'@function' command should be used in a comment attached to a function declaration}}
744/*! @function test_function
745*/
746typedef unsigned int Base64Flags;
747unsigned test_function(Base64Flags inFlags);
748
749// expected-warning@+1 {{'@callback' command should be used in a comment attached to a pointer to function declaration}}
750/*! @callback test_callback
751*/
752typedef unsigned int BaseFlags;
753unsigned (*test_callback)(BaseFlags inFlags);
754
755// expected-warning@+1 {{'\endverbatim' command does not terminate a verbatim text block}}
756/// \endverbatim
757int test_verbatim_1();
758
759// expected-warning@+1 {{'\endcode' command does not terminate a verbatim text block}}
760/// \endcode
761int test_verbatim_2();
762
763// FIXME: we give a bad diagnostic here because we throw away non-documentation
764// comments early.
765//
766// expected-warning@+3 {{'\endcode' command does not terminate a verbatim text block}}
767/// \code
768//  foo
769/// \endcode
770int test_verbatim_3();
771
772
773// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
774int test1; ///< \brief\author Aaa
775
776// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
777// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
778int test2, ///< \brief\author Aaa
779    test3; ///< \brief\author Aaa
780
781// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
782int test4; ///< \brief
783           ///< \author Aaa
784
785
786class TestRelates {};
787
788/// \relates TestRelates
789/// \brief Aaa
790void test_relates_1();
791
792/// \related TestRelates
793/// \brief Aaa
794void test_relates_2();
795
796/// \relatesalso TestRelates
797/// \brief Aaa
798void test_relates_3();
799
800/// \relatedalso TestRelates
801/// \brief Aaa
802void test_relates_4();
803
804
805// Check that we attach the comment to the declaration during parsing in the
806// following cases.  The test is based on the fact that we don't parse
807// documentation comments that are not attached to anything.
808
809// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
810/// \brief\author Aaa
811int test_attach1;
812
813// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
814/// \brief\author Aaa
815int test_attach2(int);
816
817// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
818/// \brief\author Aaa
819struct test_attach3 {
820  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
821  /// \brief\author Aaa
822  int test_attach4;
823
824  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
825  int test_attach5; ///< \brief\author Aaa
826
827  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
828  /// \brief\author Aaa
829  int test_attach6(int);
830};
831
832// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
833/// \brief\author Aaa
834class test_attach7 {
835  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
836  /// \brief\author Aaa
837  int test_attach8;
838
839  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
840  int test_attach9; ///< \brief\author Aaa
841
842  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
843  /// \brief\author Aaa
844  int test_attach10(int);
845};
846
847// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
848/// \brief\author Aaa
849enum test_attach9 {
850  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
851  /// \brief\author Aaa
852  test_attach10,
853
854  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
855  test_attach11 ///< \brief\author Aaa
856};
857
858// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
859/// \brief\author Aaa
860struct test_noattach12 *test_attach13;
861
862// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
863/// \brief\author Aaa
864typedef struct test_noattach14 *test_attach15;
865
866// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
867/// \brief\author Aaa
868typedef struct test_attach16 { int a; } test_attach17;
869
870struct S { int a; };
871
872// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
873/// \brief\author Aaa
874struct S *test_attach18;
875
876// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
877/// \brief\author Aaa
878typedef struct S *test_attach19;
879
880// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
881/// \brief\author Aaa
882struct test_attach20;
883
884// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
885/// \brief\author Aaa
886typedef struct test_attach21 {
887  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
888  /// \brief\author Aaa
889  int test_attach22;
890} test_attach23;
891
892// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
893/// \brief\author Aaa
894namespace test_attach24 {
895  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
896  /// \brief\author Aaa
897  namespace test_attach25 {
898  }
899}
900
901// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
902/// \brief\author Aaa
903/// \tparam T Aaa
904template<typename T>
905void test_attach26(T aaa);
906
907// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
908/// \brief\author Aaa
909/// \tparam T Aaa
910template<typename T, typename U>
911void test_attach27(T aaa, U bbb);
912
913// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
914// expected-warning@+2 {{template parameter 'T' not found in the template declaration}}
915/// \brief\author Aaa
916/// \tparam T Aaa
917template<>
918void test_attach27(int aaa, int bbb);
919
920// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
921/// \brief\author Aaa
922/// \tparam T Aaa
923template<typename T>
924class test_attach28 {
925  T aaa;
926};
927
928// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
929/// \brief\author Aaa
930using test_attach29 = test_attach28<int>;
931
932// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
933/// \brief\author Aaa
934/// \tparam T Aaa
935template<typename T, typename U>
936class test_attach30 { };
937
938// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
939/// \brief\author Aaa
940/// \tparam T Aaa
941template<typename T>
942class test_attach30<T, int> { };
943
944// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
945/// \brief\author Aaa
946template<>
947class test_attach30<int, int> { };
948
949// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
950/// \brief\author Aaa
951template<typename T>
952using test_attach31 = test_attach30<T, int>;
953
954// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
955/// \brief\author Aaa
956/// \tparam T Aaa
957template<typename T, typename U, typename V>
958class test_attach32 { };
959
960// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
961/// \brief\author Aaa
962/// \tparam T Aaa
963template<typename T, typename U>
964class test_attach32<T, U, int> { };
965
966// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
967/// \brief\author Aaa
968/// \tparam T Aaa
969template<typename T>
970class test_attach32<T, int, int> { };
971
972// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
973// expected-warning@+2 {{template parameter 'T' not found in the template declaration}}
974/// \brief\author Aaa
975/// \tparam T Aaa
976template<>
977class test_attach32<int, int, int> { };
978
979// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
980/// \brief\author Aaa
981class test_attach33 {
982  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
983  /// \brief\author Aaa
984  /// \tparam T Aaa
985  template<typename T, typename U>
986  void test_attach34(T aaa, U bbb);
987};
988
989template<typename T>
990class test_attach35 {
991  // expected-warning@+2 {{empty paragraph passed to '\brief' command}}
992  // expected-warning@+2 {{template parameter 'T' not found in the template declaration}}
993  /// \brief\author Aaa
994  /// \tparam T Aaa
995  template<typename TT, typename UU>
996  void test_attach36(TT aaa, UU bbb);
997};
998
999// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
1000// expected-warning@+2 {{template parameter 'T' not found in the template declaration}}
1001/// \brief\author Aaa
1002/// \tparam T Aaa
1003template<> template<>
1004void test_attach35<int>::test_attach36(int aaa, int bbb) {}
1005
1006template<typename T>
1007class test_attach37 {
1008  // expected-warning@+2 {{empty paragraph passed to '\brief' command}}
1009  // expected-warning@+2 {{'\tparam' command used in a comment that is not attached to a template declaration}}
1010  /// \brief\author Aaa
1011  /// \tparam T Aaa
1012  void test_attach38(int aaa, int bbb);
1013
1014  void test_attach39(int aaa, int bbb);
1015};
1016
1017// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
1018// expected-warning@+2 {{template parameter 'T' not found in the template declaration}}
1019/// \brief\author Aaa
1020/// \tparam T Aaa
1021template<>
1022void test_attach37<int>::test_attach38(int aaa, int bbb) {}
1023
1024// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
1025/// \brief\author Aaa
1026/// \tparam T Aaa
1027template<typename T>
1028void test_attach37<T>::test_attach39(int aaa, int bbb) {}
1029
1030// We used to emit warning that parameter 'a' is not found because we parsed
1031// the comment in context of the redeclaration which does not have parameter
1032// names.
1033template <typename T>
1034struct test_attach38 {
1035  /*!
1036    \param a  First param
1037    \param b  Second param
1038  */
1039  template <typename B>
1040  void test_attach39(T a, B b);
1041};
1042
1043template <>
1044template <typename B>
1045void test_attach38<int>::test_attach39(int, B);
1046
1047
1048// PR13411, reduced.  We used to crash on this.
1049/**
1050 * @code Aaa.
1051 */
1052void test_nocrash1(int);
1053
1054// We used to crash on this.
1055// expected-warning@+2 {{empty paragraph passed to '\param' command}}
1056// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
1057/// \param\brief
1058void test_nocrash2(int);
1059
1060// PR13593, example 1 and 2
1061
1062/**
1063* Bla.
1064*/
1065template <typename>
1066void test_nocrash3();
1067
1068/// Foo
1069template <typename, typename>
1070void test_nocrash4() { }
1071
1072template <typename>
1073void test_nocrash3()
1074{
1075}
1076
1077// PR13593, example 3
1078
1079/**
1080 * aaa
1081 */
1082template <typename T>
1083inline T test_nocrash5(T a1)
1084{
1085    return a1;
1086}
1087
1088///
1089//,
1090
1091inline void test_nocrash6()
1092{
1093    test_nocrash5(1);
1094}
1095
1096// We used to crash on this.
1097
1098/*!
1099  Blah.
1100*/
1101typedef const struct test_nocrash7 * test_nocrash8;
1102
1103// We used to crash on this.
1104
1105// expected-warning@+1 {{unknown command tag name}}
1106/// aaa \unknown aaa \unknown aaa
1107int test_nocrash9;
1108
1109// We used to crash on this.  PR15068
1110
1111// expected-warning@+2 {{empty paragraph passed to '@param' command}}
1112// expected-warning@+2 {{empty paragraph passed to '@param' command}}
1113///@param x
1114///@param y
1115int test_nocrash10(int x, int y);
1116
1117// expected-warning@+2 {{empty paragraph passed to '@param' command}} expected-warning@+2 {{parameter 'x' not found in the function declaration}}
1118// expected-warning@+2 {{empty paragraph passed to '@param' command}} expected-warning@+2 {{parameter 'y' not found in the function declaration}}
1119///@param x
1120///@param y
1121int test_nocrash11();
1122
1123// expected-warning@+3 {{empty paragraph passed to '@param' command}} expected-warning@+3 {{parameter 'x' not found in the function declaration}}
1124// expected-warning@+3 {{empty paragraph passed to '@param' command}} expected-warning@+3 {{parameter 'y' not found in the function declaration}}
1125/**
1126@param x
1127@param y
1128**/
1129int test_nocrash12();
1130
1131// expected-warning@+2 {{empty paragraph passed to '@param' command}}
1132// expected-warning@+1 {{empty paragraph passed to '@param' command}}
1133///@param x@param y
1134int test_nocrash13(int x, int y);
1135
1136/**
1137 * \verbatim
1138 * Aaa
1139 **/
1140int test_nocrash14();
1141
1142// rdar://12379114
1143// expected-warning@+2 {{'@union' command should not be used in a comment attached to a non-union declaration}}
1144/*!
1145   @union U This is new 
1146*/
1147struct U { int iS; };
1148
1149/*!
1150  @union U1
1151*/
1152union U1 {int i; };
1153
1154// expected-warning@+2 {{'@struct' command should not be used in a comment attached to a non-struct declaration}}
1155/*!
1156 @struct S2
1157*/
1158union S2 {};
1159
1160/*!
1161  @class C1
1162*/
1163class C1;
1164
1165/*!
1166  @struct S3;
1167*/
1168class S3;
1169
1170// rdar://14124702
1171//----------------------------------------------------------------------
1172/// @class Predicate Predicate.h "lldb/Host/Predicate.h"
1173/// @brief A C++ wrapper class for providing threaded access to a value
1174/// of type T.
1175///
1176/// A templatized class.
1177/// specified values.
1178//----------------------------------------------------------------------
1179template <class T, class T1>
1180class Predicate
1181{
1182};
1183
1184//----------------------------------------------------------------------
1185/// @class Predicate<int, char> Predicate.h "lldb/Host/Predicate.h"
1186/// @brief A C++ wrapper class for providing threaded access to a value
1187/// of type T.
1188///
1189/// A template specialization class.
1190//----------------------------------------------------------------------
1191template<> class Predicate<int, char>
1192{
1193};
1194
1195//----------------------------------------------------------------------
1196/// @class Predicate<T, int> Predicate.h "lldb/Host/Predicate.h"
1197/// @brief A C++ wrapper class for providing threaded access to a value
1198/// of type T.
1199///
1200/// A partial specialization template class.
1201//----------------------------------------------------------------------
1202template<class T> class Predicate<T, int>
1203{
1204};
1205
1206/*!     @function test_function
1207*/
1208template <class T> T test_function (T arg);
1209
1210/*!     @function test_function<int>
1211*/
1212template <> int test_function<int> (int arg);
1213
1214namespace AllowParamAndReturnsOnFunctionPointerVars {
1215
1216/**
1217 * functionPointerVariable
1218 *
1219 * @param i is integer.
1220 * @returns integer.
1221 */
1222int (*functionPointerVariable)(int i);
1223
1224struct HasFields {
1225  /**
1226   * functionPointerField
1227   *
1228   * @param i is integer.
1229   * @returns integer.
1230   */
1231  int (*functionPointerField)(int i);
1232};
1233
1234// expected-warning@+5 {{'\returns' command used in a comment that is attached to a function returning void}}
1235/**
1236 * functionPointerVariable
1237 *
1238 * \param p not here.
1239 * \returns integer.
1240 */
1241void (*functionPointerVariableThatLeadsNowhere)();
1242
1243// Still warn about param/returns commands for variables that don't specify
1244// the type directly:
1245
1246/**
1247 * FunctionPointerTypedef
1248 *
1249 * \param i is integer.
1250 * \returns integer.
1251 */
1252typedef int (*FunctionPointerTypedef)(int i);
1253
1254/**
1255 * FunctionPointerTypealias
1256 *
1257 * \param i is integer.
1258 * \returns integer.
1259 */
1260using FunctionPointerTypealias = int (*)(int i);
1261
1262// expected-warning@+5 {{'@param' command used in a comment that is not attached to a function declaration}}
1263// expected-warning@+5 {{'@returns' command used in a comment that is not attached to a function or method declaration}}
1264/**
1265 * functionPointerVariable
1266 *
1267 * @param i is integer.
1268 * @returns integer.
1269 */
1270FunctionPointerTypedef functionPointerTypedefVariable;
1271
1272struct HasMoreFields {
1273  // expected-warning@+5 {{'\param' command used in a comment that is not attached to a function declaration}}
1274  // expected-warning@+5 {{'\returns' command used in a comment that is not attached to a function or method declaration}}
1275  /**
1276   * functionPointerTypealiasField
1277   *
1278   * \param i is integer.
1279   * \returns integer.
1280   */
1281  FunctionPointerTypealias functionPointerTypealiasField;
1282};
1283
1284}
1285
1286/*!
1287 * Function pointer typedef with variadic params.
1288 *
1289 * @param a
1290 * works
1291 *
1292 * @param ...
1293 * now should work too.
1294 */
1295typedef void (*VariadicFnType)(int a, ...);
1296
1297/*!
1298 * Function pointer type alias with variadic params.
1299 *
1300 * @param a
1301 * works
1302 *
1303 * @param ...
1304 * now should work too.
1305 */
1306using VariadicFnType2 = void (*)(int a, ...);
1307
1308// expected-warning@+2 {{empty paragraph passed to '@note' command}}
1309/**
1310@note
1311\f$\texttt{mu}_{00}=\texttt{m}_{00}\f$, \f$\texttt{nu}_{00}=1\f$
1312\f$\texttt{nu}_{10}=\texttt{mu}_{10}=\texttt{mu}_{01}=\texttt{mu}_{10}=0\f$
1313 */
1314class EmptyNoteNoCrash {
1315};
1316