warn-documentation.cpp revision 89ab7d0012ffe02a335b765eeb9b48977a5ecd79
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic -verify %s
2
3// expected-warning@+1 {{expected quoted string after equals sign}}
4/// <a href=>
5int test_html1(int);
6
7// expected-warning@+1 {{expected quoted string after equals sign}}
8/// <a href==>
9int test_html2(int);
10
11// expected-warning@+2 {{expected quoted string after equals sign}}
12// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
13/// <a href= blah
14int test_html3(int);
15
16// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
17/// <a =>
18int test_html4(int);
19
20// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
21/// <a "aaa">
22int test_html5(int);
23
24// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
25/// <a a="b" =>
26int test_html6(int);
27
28// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
29/// <a a="b" "aaa">
30int test_html7(int);
31
32// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
33/// <a a="b" =
34int test_html8(int);
35
36// expected-warning@+2 {{HTML start tag prematurely ended, expected attribute name or '>'}} expected-note@+1 {{HTML tag started here}}
37/** Aaa bbb<ccc ddd eee
38 * fff ggg.
39 */
40int test_html9(int);
41
42// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}}
43/** Aaa bbb<ccc ddd eee 42%
44 * fff ggg.
45 */
46int test_html10(int);
47
48// expected-warning@+1 {{HTML end tag 'br' is forbidden}}
49/// <br></br>
50int test_html11(int);
51
52/// <blockquote>Meow</blockquote>
53int test_html_nesting1(int);
54
55/// <b><i>Meow</i></b>
56int test_html_nesting2(int);
57
58/// <p>Aaa<br>
59/// Bbb</p>
60int test_html_nesting3(int);
61
62/// <p>Aaa<br />
63/// Bbb</p>
64int test_html_nesting4(int);
65
66// expected-warning@+1 {{HTML end tag does not match any start tag}}
67/// <b><i>Meow</a>
68int test_html_nesting5(int);
69
70// expected-warning@+2 {{HTML start tag 'i' closed by 'b'}}
71// expected-warning@+1 {{HTML end tag does not match any start tag}}
72/// <b><i>Meow</b></b>
73int test_html_nesting6(int);
74
75// expected-warning@+2 {{HTML start tag 'i' closed by 'b'}}
76// expected-warning@+1 {{HTML end tag does not match any start tag}}
77/// <b><i>Meow</b></i>
78int test_html_nesting7(int);
79
80
81// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
82/// \brief\brief Aaa
83int test_block_command1(int);
84
85// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
86/// \brief \brief Aaa
87int test_block_command2(int);
88
89// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
90/// \brief
91/// \brief Aaa
92int test_block_command3(int);
93
94// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
95/// \brief
96///
97/// \brief Aaa
98int test_block_command4(int);
99
100// There is trailing whitespace on one of the following lines, don't remove it!
101// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
102/// \brief
103///
104/// \brief Aaa
105int test_block_command5(int);
106
107/// \brief \c Aaa
108int test_block_command6(int);
109
110// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
111/// \param a Blah blah.
112int test_param1;
113
114// expected-warning@+1 {{empty paragraph passed to '\param' command}}
115/// \param
116/// \param a Blah blah.
117int test_param2(int a);
118
119// expected-warning@+1 {{empty paragraph passed to '\param' command}}
120/// \param a
121int test_param3(int a);
122
123/// \param a Blah blah.
124int test_param4(int a);
125
126/// \param [in] a Blah blah.
127int test_param5(int a);
128
129/// \param [out] a Blah blah.
130int test_param6(int a);
131
132/// \param [in,out] a Blah blah.
133int test_param7(int a);
134
135// expected-warning@+1 {{whitespace is not allowed in parameter passing direction}}
136/// \param [ in ] a Blah blah.
137int test_param8(int a);
138
139// expected-warning@+1 {{whitespace is not allowed in parameter passing direction}}
140/// \param [in, out] a Blah blah.
141int test_param9(int a);
142
143// expected-warning@+1 {{unrecognized parameter passing direction, valid directions are '[in]', '[out]' and '[in,out]'}}
144/// \param [ junk] a Blah blah.
145int test_param10(int a);
146
147// expected-warning@+1 {{parameter 'a' not found in the function declaration}}
148/// \param a Blah blah.
149int test_param11();
150
151// expected-warning@+1 {{parameter 'A' not found in the function declaration}} expected-note@+1 {{did you mean 'a'?}}
152/// \param A Blah blah.
153int test_param12(int a);
154
155// expected-warning@+1 {{parameter 'aab' not found in the function declaration}} expected-note@+1 {{did you mean 'aaa'?}}
156/// \param aab Blah blah.
157int test_param13(int aaa, int bbb);
158
159// expected-warning@+1 {{parameter 'aab' not found in the function declaration}}
160/// \param aab Blah blah.
161int test_param14(int bbb, int ccc);
162
163class C {
164  // expected-warning@+1 {{parameter 'aaa' not found in the function declaration}}
165  /// \param aaa Blah blah.
166  C(int bbb, int ccc);
167
168  // expected-warning@+1 {{parameter 'aaa' not found in the function declaration}}
169  /// \param aaa Blah blah.
170 int test_param15(int bbb, int ccc);
171};
172
173// expected-warning@+1 {{parameter 'aab' not found in the function declaration}}
174/// \param aab Blah blah.
175template<typename T>
176void test_param16(int bbb, int ccc);
177
178// expected-warning@+3 {{parameter 'a' is already documented}}
179// expected-note@+1 {{previous documentation}}
180/// \param a Aaa.
181/// \param a Aaa.
182int test_param17(int a);
183
184// expected-warning@+4 {{parameter 'x2' is already documented}}
185// expected-note@+2 {{previous documentation}}
186/// \param x1 Aaa.
187/// \param x2 Bbb.
188/// \param x2 Ccc.
189int test_param18(int x1, int x2, int x3);
190
191
192// expected-warning@+1 {{'\tparam' command used in a comment that is not attached to a template declaration}}
193/// \tparam T Aaa
194int test_tparam1;
195
196// expected-warning@+1 {{'\tparam' command used in a comment that is not attached to a template declaration}}
197/// \tparam T Aaa
198void test_tparam2(int aaa);
199
200// expected-warning@+1 {{empty paragraph passed to '\tparam' command}}
201/// \tparam
202/// \param aaa Blah blah
203template<typename T>
204void test_tparam3(T aaa);
205
206// expected-warning@+1 {{template parameter 'T' not found in the template declaration}} expected-note@+1 {{did you mean 'TT'?}}
207/// \tparam T Aaa
208template<typename TT>
209void test_tparam4(TT aaa);
210
211// expected-warning@+1 {{template parameter 'T' not found in the template declaration}} expected-note@+1 {{did you mean 'TT'?}}
212/// \tparam T Aaa
213template<typename TT>
214class test_tparam5 {
215  // expected-warning@+1 {{template parameter 'T' not found in the template declaration}} expected-note@+1 {{did you mean 'TTT'?}}
216  /// \tparam T Aaa
217  template<typename TTT>
218  void test_tparam6(TTT aaa);
219};
220
221/// \tparam T1 Aaa
222/// \tparam T2 Bbb
223template<typename T1, typename T2>
224void test_tparam7(T1 aaa, T2 bbb);
225
226// expected-warning@+1 {{template parameter 'SomTy' not found in the template declaration}} expected-note@+1 {{did you mean 'SomeTy'?}}
227/// \tparam SomTy Aaa
228/// \tparam OtherTy Bbb
229template<typename SomeTy, typename OtherTy>
230void test_tparam8(SomeTy aaa, OtherTy bbb);
231
232// expected-warning@+2 {{template parameter 'T1' is already documented}} expected-note@+1 {{previous documentation}}
233/// \tparam T1 Aaa
234/// \tparam T1 Bbb
235template<typename T1, typename T2>
236void test_tparam9(T1 aaa, T2 bbb);
237
238/// \tparam T Aaa
239/// \tparam TT Bbb
240template<template<typename T> class TT>
241void test_tparam10(TT<int> aaa);
242
243/// \tparam T Aaa
244/// \tparam TT Bbb
245/// \tparam TTT Ccc
246template<template<template<typename T> class TT, class C> class TTT>
247void test_tparam11();
248
249/// \tparam I Aaa
250template<int I>
251void test_tparam12();
252
253template<typename T, typename U>
254class test_tparam13 { };
255
256/// \tparam T Aaa
257template<typename T>
258using test_tparam14 = test_tparam13<T, int>;
259
260// expected-warning@+1 {{template parameter 'U' not found in the template declaration}} expected-note@+1 {{did you mean 'T'?}}
261/// \tparam U Aaa
262template<typename T>
263using test_tparam15 = test_tparam13<T, int>;
264
265// no-warning
266/// \returns Aaa
267int test_returns_right_decl_1(int);
268
269class test_returns_right_decl_2 {
270  // no-warning
271  /// \returns Aaa
272  int test_returns_right_decl_3(int);
273};
274
275// no-warning
276/// \returns Aaa
277template<typename T>
278int test_returns_right_decl_4(T aaa);
279
280// no-warning
281/// \returns Aaa
282template<>
283int test_returns_right_decl_4(int aaa);
284
285/// \returns Aaa
286template<typename T>
287T test_returns_right_decl_5(T aaa);
288
289// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function declaration}}
290/// \returns Aaa
291int test_returns_wrong_decl_1;
292
293// expected-warning@+1 {{'\return' command used in a comment that is not attached to a function declaration}}
294/// \return Aaa
295int test_returns_wrong_decl_2;
296
297// expected-warning@+1 {{'\result' command used in a comment that is not attached to a function declaration}}
298/// \result Aaa
299int test_returns_wrong_decl_3;
300
301// expected-warning@+1 {{'\returns' command used in a comment that is attached to a void function}}
302/// \returns Aaa
303void test_returns_wrong_decl_4(int);
304
305// expected-warning@+1 {{'\returns' command used in a comment that is attached to a void function}}
306/// \returns Aaa
307template<typename T>
308void test_returns_wrong_decl_5(T aaa);
309
310// expected-warning@+1 {{'\returns' command used in a comment that is attached to a void function}}
311/// \returns Aaa
312template<>
313void test_returns_wrong_decl_5(int aaa);
314
315// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function declaration}}
316/// \returns Aaa
317struct test_returns_wrong_decl_6 { };
318
319// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function declaration}}
320/// \returns Aaa
321class test_returns_wrong_decl_7 {
322  // expected-warning@+1 {{'\returns' command used in a comment that is attached to a constructor}}
323  /// \returns Aaa
324  test_returns_wrong_decl_7();
325
326  // expected-warning@+1 {{'\returns' command used in a comment that is attached to a destructor}}
327  /// \returns Aaa
328  ~test_returns_wrong_decl_7();
329};
330
331// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function declaration}}
332/// \returns Aaa
333enum test_returns_wrong_decl_8 {
334  // expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function declaration}}
335  /// \returns Aaa
336  test_returns_wrong_decl_9
337};
338
339// expected-warning@+1 {{'\returns' command used in a comment that is not attached to a function declaration}}
340/// \returns Aaa
341namespace test_returns_wrong_decl_10 { };
342
343
344// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
345int test1; ///< \brief\brief Aaa
346
347// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
348// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
349int test2, ///< \brief\brief Aaa
350    test3; ///< \brief\brief Aaa
351
352// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
353int test4; ///< \brief
354           ///< \brief Aaa
355
356
357// Check that we attach the comment to the declaration during parsing in the
358// following cases.  The test is based on the fact that we don't parse
359// documentation comments that are not attached to anything.
360
361// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
362/// \brief\brief Aaa
363int test_attach1;
364
365// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
366/// \brief\brief Aaa
367int test_attach2(int);
368
369// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
370/// \brief\brief Aaa
371struct test_attach3 {
372  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
373  /// \brief\brief Aaa
374  int test_attach4;
375
376  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
377  int test_attach5; ///< \brief\brief Aaa
378
379  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
380  /// \brief\brief Aaa
381  int test_attach6(int);
382};
383
384// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
385/// \brief\brief Aaa
386class test_attach7 {
387  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
388  /// \brief\brief Aaa
389  int test_attach8;
390
391  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
392  int test_attach9; ///< \brief\brief Aaa
393
394  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
395  /// \brief\brief Aaa
396  int test_attach10(int);
397};
398
399// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
400/// \brief\brief Aaa
401enum test_attach9 {
402  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
403  /// \brief\brief Aaa
404  test_attach10,
405
406  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
407  test_attach11 ///< \brief\brief Aaa
408};
409
410// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
411/// \brief\brief Aaa
412struct test_noattach12 *test_attach13;
413
414// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
415/// \brief\brief Aaa
416typedef struct test_noattach14 *test_attach15;
417
418// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
419/// \brief\brief Aaa
420typedef struct test_attach16 { int a; } test_attach17;
421
422struct S { int a; };
423
424// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
425/// \brief\brief Aaa
426struct S *test_attach18;
427
428// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
429/// \brief\brief Aaa
430typedef struct S *test_attach19;
431
432// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
433/// \brief\brief Aaa
434struct test_attach20;
435
436// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
437/// \brief\brief Aaa
438typedef struct test_attach21 {
439  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
440  /// \brief\brief Aaa
441  int test_attach22;
442} test_attach23;
443
444// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
445/// \brief\brief Aaa
446namespace test_attach24 {
447  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
448  /// \brief\brief Aaa
449  namespace test_attach25 {
450  }
451}
452
453// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
454/// \brief\brief Aaa
455/// \tparam T Aaa
456template<typename T>
457void test_attach26(T aaa);
458
459// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
460/// \brief\brief Aaa
461/// \tparam T Aaa
462template<typename T, typename U>
463void test_attach27(T aaa, U bbb);
464
465// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
466// expected-warning@+2 {{template parameter 'T' not found in the template declaration}}
467/// \brief\brief Aaa
468/// \tparam T Aaa
469template<>
470void test_attach27(int aaa, int bbb);
471
472// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
473/// \brief\brief Aaa
474/// \tparam T Aaa
475template<typename T>
476class test_attach28 {
477  T aaa;
478};
479
480// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
481/// \brief\brief Aaa
482using test_attach29 = test_attach28<int>;
483
484// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
485/// \brief\brief Aaa
486/// \tparam T Aaa
487template<typename T, typename U>
488class test_attach30 { };
489
490// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
491/// \brief\brief Aaa
492/// \tparam T Aaa
493template<typename T>
494class test_attach30<T, int> { };
495
496// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
497/// \brief\brief Aaa
498template<>
499class test_attach30<int, int> { };
500
501// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
502/// \brief\brief Aaa
503template<typename T>
504using test_attach31 = test_attach30<T, int>;
505
506// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
507/// \brief\brief Aaa
508/// \tparam T Aaa
509template<typename T, typename U, typename V>
510class test_attach32 { };
511
512// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
513/// \brief\brief Aaa
514/// \tparam T Aaa
515template<typename T, typename U>
516class test_attach32<T, U, int> { };
517
518// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
519/// \brief\brief Aaa
520/// \tparam T Aaa
521template<typename T>
522class test_attach32<T, int, int> { };
523
524// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
525// expected-warning@+2 {{template parameter 'T' not found in the template declaration}}
526/// \brief\brief Aaa
527/// \tparam T Aaa
528template<>
529class test_attach32<int, int, int> { };
530
531// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
532/// \brief\brief Aaa
533class test_attach33 {
534  // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
535  /// \brief\brief Aaa
536  /// \tparam T Aaa
537  template<typename T, typename U>
538  void test_attach34(T aaa, U bbb);
539};
540
541template<typename T>
542class test_attach35 {
543  // expected-warning@+2 {{empty paragraph passed to '\brief' command}}
544  // expected-warning@+2 {{template parameter 'T' not found in the template declaration}}
545  /// \brief\brief Aaa
546  /// \tparam T Aaa
547  template<typename TT, typename UU>
548  void test_attach36(TT aaa, UU bbb);
549};
550
551// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
552// expected-warning@+2 {{template parameter 'T' not found in the template declaration}}
553/// \brief\brief Aaa
554/// \tparam T Aaa
555template<> template<>
556void test_attach35<int>::test_attach36(int aaa, int bbb) {}
557
558template<typename T>
559class test_attach37 {
560  // expected-warning@+2 {{empty paragraph passed to '\brief' command}}
561  // expected-warning@+2 {{'\tparam' command used in a comment that is not attached to a template declaration}}
562  /// \brief\brief Aaa
563  /// \tparam T Aaa
564  void test_attach38(int aaa, int bbb);
565};
566
567// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
568/// \brief\brief Aaa
569/// \tparam T Aaa
570template<typename T>
571void test_attach37<T>::test_attach38(int aaa, int bbb) {}
572
573// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
574// expected-warning@+2 {{template parameter 'T' not found in the template declaration}}
575/// \brief\brief Aaa
576/// \tparam T Aaa
577template<>
578void test_attach37<int>::test_attach38(int aaa, int bbb) {}
579
580
581// PR13411, reduced.  We used to crash on this.
582/**
583 * @code Aaa.
584 */
585void test_nocrash1(int);
586
587// We used to crash on this.
588// expected-warning@+2 {{empty paragraph passed to '\param' command}}
589// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
590/// \param\brief
591void test_nocrash2(int);
592
593