warn-documentation.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation -Wdocumentation-pedantic -verify %s
  2. @class NSString;
  3. // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
  4. /// \brief\author Aaa
  5. @interface Test1
  6. // expected-warning@+2 {{empty paragraph passed to '\brief' command}}
  7. /**
  8. * \brief\author Aaa
  9. * \param aaa Aaa
  10. * \param bbb Bbb
  11. */
  12. + (NSString *)test1:(NSString *)aaa suffix:(NSString *)bbb;
  13. // expected-warning@+2 {{parameter 'aab' not found in the function declaration}} expected-note@+2 {{did you mean 'aaa'?}}
  14. /**
  15. * \param aab Aaa
  16. */
  17. + (NSString *)test2:(NSString *)aaa;
  18. // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
  19. /// \brief\author Aaa
  20. @property int test3; // a property: ObjCPropertyDecl
  21. // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
  22. /// \brief\author Aaa
  23. @property int test4; // a property: ObjCPropertyDecl
  24. @end
  25. // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
  26. /// \brief\author Aaa
  27. @interface Test1()
  28. @end
  29. // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
  30. /// \brief\author Aaa
  31. @implementation Test1 // a class implementation : ObjCImplementationDecl
  32. + (NSString *)test1:(NSString *)aaa suffix:(NSString *)bbb {
  33. return 0;
  34. }
  35. + (NSString *)test2:(NSString *)aaa {
  36. return 0;
  37. }
  38. @synthesize test3; // a property implementation: ObjCPropertyImplDecl
  39. @dynamic test4; // a property implementation: ObjCPropertyImplDecl
  40. // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
  41. /// \brief\author Aaa
  42. NSString *_test5;
  43. @end
  44. // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
  45. /// \brief\author Aaa
  46. @interface Test1(Test1Category) // a category: ObjCCategoryDecl
  47. // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
  48. /// \brief\author Aaa
  49. + (NSString *)test3:(NSString *)aaa;
  50. @end
  51. // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
  52. /// \brief\author Aaa
  53. @implementation Test1(Test1Category) // a category implementation: ObjCCategoryImplDecl
  54. + (NSString *)test3:(NSString *)aaa {
  55. return 0;
  56. }
  57. @end
  58. // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
  59. /// \brief\author Aaa
  60. @protocol TestProto1 // a protocol: ObjCProtocolDecl
  61. @end
  62. int a;
  63. // expected-warning@+1 {{empty paragraph passed to '\brief' command}}
  64. /// \brief\author Aaa
  65. @interface Test4
  66. @end
  67. int b;
  68. @interface TestReturns1
  69. /// \returns Aaa
  70. - (int)test1:(NSString *)aaa;
  71. // expected-warning@+1 {{'\returns' command used in a comment that is attached to a method returning void}}
  72. /// \returns Aaa
  73. - (void)test2:(NSString *)aaa;
  74. @end
  75. // expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
  76. /// \param aaa Meow.
  77. /// \param bbb Bbb.
  78. /// \returns aaa.
  79. typedef int (^test_param1)(int aaa, int ccc);
  80. // rdar://13094352
  81. // expected-warning@+2 {{'@method' command should be used in a comment attached to an Objective-C method declaration}}
  82. @interface I
  83. /*! @method Base64EncodeEx
  84. */
  85. typedef id ID;
  86. - (unsigned) Base64EncodeEx : (ID)Arg;
  87. @end
  88. // rdar://12379114
  89. // expected-warning@+5 {{'@interface' command should not be used in a comment attached to a non-interface declaration}}
  90. // expected-warning@+5 {{'@classdesign' command should not be used in a comment attached to a non-container declaration}}
  91. // expected-warning@+5 {{'@coclass' command should not be used in a comment attached to a non-container declaration}}
  92. @interface NSObject @end
  93. /*!
  94. @interface IOCommandGate
  95. @classdesign Multiple paragraphs go here.
  96. @coclass myCoClass
  97. */
  98. typedef id OBJ;
  99. @interface IOCommandGate : NSObject {
  100. OBJ iv;
  101. }
  102. @end
  103. // rdar://12379114
  104. // expected-warning@+4 {{'@methodgroup' command should be used in a comment attached to an Objective-C method declaration}}
  105. // expected-warning@+6 {{'@method' command should be used in a comment attached to an Objective-C method declaratio}}
  106. @interface rdar12379114
  107. /*!
  108. @methodgroup Creating a request
  109. */
  110. /*!
  111. @method initWithTimeout is the 2nd method
  112. */
  113. typedef unsigned int NSTimeInterval;
  114. - (id)initWithTimeout:(NSTimeInterval)timeout;
  115. @end
  116. // expected-warning@+2 {{'@protocol' command should not be used in a comment attached to a non-protocol declaration}}
  117. /*!
  118. @protocol PROTO
  119. */
  120. struct S;
  121. /*!
  122. @interface NSArray This is an array
  123. */
  124. @class NSArray;
  125. @interface NSArray @end
  126. // expected-warning@+3 {{unknown command tag name}}
  127. /*!
  128. @interface NSMutableArray
  129. @super NSArray
  130. */
  131. @interface NSMutableArray : NSArray @end
  132. /*!
  133. @protocol MyProto
  134. */
  135. @protocol MyProto @end
  136. // expected-warning@+2 {{'@protocol' command should not be used in a comment attached to a non-protocol declaration}}
  137. /*!
  138. @protocol MyProto
  139. */
  140. @interface INTF <MyProto> @end
  141. // expected-warning@+2 {{'@struct' command should not be used in a comment attached to a non-struct declaration}}
  142. /*!
  143. @struct S1 THIS IS IT
  144. */
  145. @interface S1 @end
  146. // expected-warning@+1 {{unknown command tag name}}
  147. /// \t bbb IS_DOXYGEN_END
  148. int FooBar();
  149. // rdar://13836387
  150. /** \brief Module handling the incoming notifications from the system.
  151. *
  152. * This includes:
  153. * - Network Reachability
  154. * - Power State
  155. * - Low Disk
  156. */
  157. @interface BRC : NSObject
  158. - (void)removeReach:(NSObject*)observer;
  159. @end
  160. @implementation BRC : NSObject
  161. - (void)removeReach:(NSObject*)observer // expected-note {{previous declaration is here}}
  162. {
  163. }
  164. - (void)removeReach:(NSObject*)observer // expected-error {{duplicate declaration of method 'removeReach:'}}
  165. {
  166. }
  167. @end
  168. // rdar://13927330
  169. /// @class Asset <- '@class' may be used in a comment attached to a an interface declaration
  170. @interface Asset : NSObject
  171. @end
  172. // rdar://14024851 Check that this does not enter an infinite loop
  173. @interface rdar14024851
  174. -(void)meth; // expected-note {{declared here}}
  175. @end
  176. @implementation rdar14024851 // expected-warning {{method definition for 'meth' not found}} expected-note {{previous definition}}
  177. @end
  178. @implementation rdar14024851 // expected-error {{reimplementation}}
  179. /// \brief comment
  180. -(void)meth {}
  181. @end
  182. // rdar://14124644
  183. @interface test_vararg1
  184. /// @param[in] arg something
  185. /// @param[in] ... This is vararg
  186. - (void) VarArgMeth : (id)arg, ...;
  187. @end
  188. @implementation test_vararg1
  189. /// @param[in] arg something
  190. /// @param[in] ... This is vararg
  191. - (void) VarArgMeth : (id)arg, ... {}
  192. @end
  193. /**
  194. * blockPointerVariable
  195. *
  196. * @param i is integer.
  197. * @returns integer.
  198. */
  199. int (^blockPointerVariable)(int i);
  200. struct HasFields {
  201. /**
  202. * blockPointerField
  203. *
  204. * \param i is integer.
  205. * \returns integer.
  206. */
  207. int (^blockPointerFields)(int i);
  208. };
  209. // expected-warning@+5 {{'\returns' command used in a comment that is attached to a function returning void}}
  210. /**
  211. * functionPointerVariable
  212. *
  213. * \param p not here.
  214. * \returns integer.
  215. */
  216. void (^_Nullable blockPointerVariableThatLeadsNowhere)();
  217. @interface CheckFunctionBlockPointerVars {
  218. /**
  219. * functionPointerIVar
  220. *
  221. * @param i is integer.
  222. * @returns integer.
  223. */
  224. int (*functionPointerIVar)(int i);
  225. /**
  226. * blockPointerIVar
  227. *
  228. * \param i is integer.
  229. * \returns integer.
  230. */
  231. int (^blockPointerIVar)(int i);
  232. }
  233. /**
  234. * functionPointerProperty
  235. *
  236. * @param i is integer.
  237. * @returns integer.
  238. */
  239. @property int (*functionPointerProperty)(int i);
  240. /**
  241. * blockPointerProperty
  242. *
  243. * \param i is integer.
  244. * \returns integer.
  245. */
  246. @property int (^blockPointerProperty)(int i);
  247. /**
  248. * blockReturnsNothing
  249. *
  250. * \returns Nothing, but can allow this as this pattern is used to document the
  251. * value that the property getter returns.
  252. */
  253. @property void (^blockReturnsNothing)();
  254. @end
  255. /*!
  256. * Block typedef with variadic params.
  257. *
  258. * @param a
  259. * works
  260. *
  261. * @param ...
  262. * now should work too.
  263. */
  264. typedef void (^VariadicBlockType)(int a, ...);
  265. // PR42844 - Assertion failures when using typedefed block pointers
  266. typedef void(^VoidBlockType)();
  267. typedef VoidBlockType VoidBlockTypeCall();
  268. VoidBlockTypeCall *d; ///< \return none
  269. // expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
  270. VoidBlockTypeCall ^e; ///< \return none
  271. // expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}}