comment-cplus-decls.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // RUN: rm -rf %t
  2. // RUN: mkdir %t
  3. // RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng -target x86_64-apple-darwin10 %s > %t/out
  4. // RUN: FileCheck %s < %t/out
  5. // RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng -target x86_64-apple-darwin10 -std=c++98 %s > %t/98
  6. // RUN: FileCheck %s < %t/98
  7. // RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng -target x86_64-apple-darwin10 -std=c++11 %s > %t/11
  8. // RUN: FileCheck %s < %t/11
  9. // Ensure that XML we generate is not invalid.
  10. // RUN: FileCheck %s -check-prefix=WRONG < %t/out
  11. // RUN: FileCheck %s -check-prefix=WRONG < %t/98
  12. // RUN: FileCheck %s -check-prefix=WRONG < %t/11
  13. // WRONG-NOT: CommentXMLInvalid
  14. // rdar://12378714
  15. /**
  16. * \brief plain c++ class
  17. */
  18. class Test
  19. {
  20. public:
  21. /**
  22. * \brief plain c++ constructor
  23. */
  24. Test () : reserved (new data()) {}
  25. /**
  26. * \brief plain c++ member function
  27. */
  28. unsigned getID() const
  29. {
  30. return reserved->objectID;
  31. }
  32. /**
  33. * \brief plain c++ destructor
  34. */
  35. ~Test () {}
  36. protected:
  37. struct data {
  38. unsigned objectID;
  39. };
  40. /**
  41. * \brief plain c++ data field
  42. */
  43. data* reserved;
  44. };
  45. // CHECK: <Declaration>class Test {}</Declaration>
  46. // CHECK: <Declaration>Test() : reserved(new Test::data()) {}</Declaration>
  47. // CHECK: <Declaration>unsigned int getID() const</Declaration>
  48. // CHECK: <Declaration>~Test(){{( noexcept)?}}</Declaration>
  49. // CHECK: <Declaration>Test::data *reserved</Declaration>
  50. class S {
  51. /**
  52. * \brief Aaa
  53. */
  54. friend class Test;
  55. /**
  56. * \brief Bbb
  57. */
  58. friend void foo() {}
  59. /**
  60. * \brief Ccc
  61. */
  62. friend int int_func();
  63. /**
  64. * \brief Ddd
  65. */
  66. friend bool operator==(const Test &, const Test &);
  67. /**
  68. * \brief Eee
  69. */
  70. template <typename T> friend void TemplateFriend();
  71. /**
  72. * \brief Eee
  73. */
  74. template <typename T> friend class TemplateFriendClass;
  75. };
  76. // CHECK: <Declaration>friend class Test</Declaration>
  77. // CHECK: <Declaration>friend void foo()</Declaration>
  78. // CHECK: <Declaration>friend int int_func()</Declaration>
  79. // CHECK: <Declaration>friend bool operator==(const Test &amp;, const Test &amp;)</Declaration>
  80. // CHECK: <Declaration>friend template &lt;typename T&gt; void TemplateFriend()</Declaration>
  81. // CHECK: <Declaration>friend template &lt;typename T&gt; class TemplateFriendClass</Declaration>
  82. namespace test0 {
  83. namespace ns {
  84. void f(int);
  85. }
  86. struct A {
  87. /**
  88. * \brief Fff
  89. */
  90. friend void ns::f(int a);
  91. };
  92. }
  93. // CHECK: <Declaration>friend void ns::f(int a)</Declaration>
  94. namespace test1 {
  95. template <class T> struct Outer {
  96. void foo(T);
  97. struct Inner {
  98. /**
  99. * \brief Ggg
  100. */
  101. friend void Outer::foo(T);
  102. };
  103. };
  104. }
  105. // CHECK: <Declaration>friend void Outer&lt;T&gt;::foo(T)</Declaration>
  106. namespace test2 {
  107. namespace foo {
  108. void Func(int x);
  109. }
  110. class Bar {
  111. /**
  112. * \brief Hhh
  113. */
  114. friend void ::test2::foo::Func(int x);
  115. };
  116. }
  117. // CHECK: <Declaration>friend void ::test2::foo::Func(int x)</Declaration>
  118. namespace test3 {
  119. template<class T> class vector {
  120. public:
  121. vector(int i) {}
  122. /**
  123. * \brief Iii
  124. */
  125. void f(const T& t = T()) {}
  126. };
  127. class A {
  128. private:
  129. /**
  130. * \brief Jjj
  131. */
  132. friend void vector<A>::f(const A&);
  133. };
  134. }
  135. // CHECK: <Declaration>void f(const T &amp;t = T())</Declaration>
  136. // CHECK: <Declaration>friend void vector&lt;A&gt;::f(const test3::A &amp;)</Declaration>
  137. class MyClass
  138. {
  139. /**
  140. * \brief plain friend test.
  141. */
  142. friend class MyClass;
  143. };
  144. // CHECK: <Declaration>friend class MyClass</Declaration>
  145. template<class _Tp> class valarray
  146. {
  147. private:
  148. /**
  149. * \brief template friend test.
  150. */
  151. template <class T> friend class valarray;
  152. };
  153. // CHECK: <Declaration>template &lt;class T&gt; class valarray</Declaration>
  154. // CHECK: <Declaration>friend template &lt;class T&gt; class valarray</Declaration>
  155. class gslice
  156. {
  157. valarray<unsigned> __size_;
  158. };