recovery.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // RUN: %clang_cc1 -verify -std=c++11 -fms-extensions %s
  2. 8gi///===--- recovery.cpp ---===// // expected-error {{unqualified-id}}
  3. namespace Std { // expected-note {{here}}
  4. typedef int Important;
  5. }
  6. / redeclare as an inline namespace // expected-error {{unqualified-id}}
  7. inline namespace Std { // expected-error {{cannot be reopened as inline}}
  8. Important n;
  9. } / end namespace Std // expected-error {{unqualified-id}}
  10. int x;
  11. Std::Important y;
  12. extenr "C" { // expected-error {{did you mean 'extern'}}
  13. void f();
  14. }
  15. void g() {
  16. z = 1; // expected-error {{undeclared}}
  17. f();
  18. }
  19. struct S {
  20. int a, b, c;
  21. S();
  22. int x // expected-error {{expected ';'}}
  23. friend void f()
  24. };
  25. 8S::S() : a{ 5 }, b{ 6 }, c{ 2 } { // expected-error {{unqualified-id}}
  26. return;
  27. }
  28. int k;
  29. int l = k // expected-error {{expected ';'}}
  30. constexpr int foo();
  31. 5int m = { l }, n = m; // expected-error {{unqualified-id}}
  32. namespace MissingBrace {
  33. struct S { // expected-error {{missing '}' at end of definition of 'MissingBrace::S'}}
  34. int f();
  35. // };
  36. namespace N { int g(); } // expected-note {{still within definition of 'MissingBrace::S' here}}
  37. int k1 = S().h(); // expected-error {{no member named 'h' in 'MissingBrace::S'}}
  38. int k2 = S().f() + N::g();
  39. template<typename T> struct PR17949 { // expected-error {{missing '}' at end of definition of 'MissingBrace::PR17949'}}
  40. namespace X { // expected-note {{still within definition of 'MissingBrace::PR17949' here}}
  41. }
  42. }
  43. namespace N {
  44. int
  45. } // expected-error {{unqualified-id}}
  46. strcut Uuuu { // expected-error {{did you mean 'struct'}} \
  47. // expected-note {{'Uuuu' declared here}}
  48. } *u[3];
  49. uuuu v; // expected-error {{did you mean 'Uuuu'}}
  50. struct Redefined { // expected-note {{previous}}
  51. Redefined() {}
  52. };
  53. struct Redefined { // expected-error {{redefinition}}
  54. Redefined() {}
  55. };
  56. struct MissingSemi5;
  57. namespace N {
  58. typedef int afterMissingSemi4;
  59. extern MissingSemi5 afterMissingSemi5;
  60. }
  61. struct MissingSemi1 {} // expected-error {{expected ';' after struct}}
  62. static int afterMissingSemi1();
  63. class MissingSemi2 {} // expected-error {{expected ';' after class}}
  64. MissingSemi1 *afterMissingSemi2;
  65. enum MissingSemi3 {} // expected-error {{expected ';' after enum}}
  66. ::MissingSemi1 afterMissingSemi3;
  67. extern N::afterMissingSemi4 afterMissingSemi4b;
  68. union MissingSemi4 { MissingSemi4(int); } // expected-error {{expected ';' after union}}
  69. N::afterMissingSemi4 (afterMissingSemi4b);
  70. int afterMissingSemi5b;
  71. struct MissingSemi5 { MissingSemi5(int); } // ok, no missing ';' here
  72. N::afterMissingSemi5 (afterMissingSemi5b);
  73. template<typename T> struct MissingSemiT {
  74. } // expected-error {{expected ';' after struct}}
  75. MissingSemiT<int> msi;
  76. struct MissingSemiInStruct {
  77. struct Inner1 {} // expected-error {{expected ';' after struct}}
  78. static MissingSemi5 ms1;
  79. struct Inner2 {} // ok, no missing ';' here
  80. static MissingSemi1;
  81. struct Inner3 {} // expected-error {{expected ';' after struct}}
  82. static MissingSemi5 *p;
  83. };
  84. void MissingSemiInFunction() {
  85. struct Inner1 {} // expected-error {{expected ';' after struct}}
  86. if (true) {}
  87. // FIXME: It would be nice to at least warn on this.
  88. struct Inner2 { Inner2(int); } // ok, no missing ';' here
  89. k = l;
  90. struct Inner3 {} // expected-error {{expected ';' after struct}}
  91. Inner1 i1;
  92. struct Inner4 {} // ok, no missing ';' here
  93. Inner5;
  94. }
  95. namespace NS {
  96. template<typename T> struct Foo {};
  97. }
  98. struct MissingSemiThenTemplate1 {} // expected-error {{expected ';' after struct}}
  99. NS::Foo<int> missingSemiBeforeFunctionReturningTemplateId1();
  100. using NS::Foo;
  101. struct MissingSemiThenTemplate2 {} // expected-error {{expected ';' after struct}}
  102. Foo<int> missingSemiBeforeFunctionReturningTemplateId2();
  103. namespace PR17084 {
  104. enum class EnumID {};
  105. template <typename> struct TempID;
  106. template <> struct TempID<BadType> : BadType, EnumID::Garbage; // expected-error{{use of undeclared identifier 'BadType'}}
  107. }
  108. namespace pr15133 {
  109. namespace ns {
  110. const int V1 = 1; // expected-note {{declared here}}
  111. }
  112. struct C1 {
  113. enum E1 { V2 = 2 }; // expected-note {{declared here}}
  114. static const int V3 = 3; // expected-note {{declared here}}
  115. };
  116. enum E2 {
  117. V4 = 4, // expected-note {{declared here}}
  118. V6 // expected-note {{declared here}}
  119. };
  120. enum class EC3 { V0 = 0, V5 = 5 }; // expected-note {{declared here}}
  121. void func_3();
  122. void func_1(int x) {
  123. switch(x) {
  124. case 0: break;
  125. case ns::V1:: break; // expected-error{{'V1' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
  126. case C1::V2:: break; // expected-error{{'V2' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
  127. case C1::V3:: break; // expected-error{{'V3' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
  128. case V4:: break; // expected-error{{'V4' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
  129. case V6:: func_3(); // expected-error{{'V6' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
  130. }
  131. }
  132. void func_2(EC3 x) {
  133. switch(x) {
  134. case EC3::V0: break;
  135. case EC3::V5:: break; // expected-error{{'V5' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
  136. }
  137. }
  138. template<class T> struct TS1 {
  139. typedef int A;
  140. };
  141. template<class T> void func(int x) {
  142. switch(x) {
  143. case TS1<T>::A:: break; // expected-error{{expected unqualified-id}}
  144. }
  145. };
  146. void mainf() {
  147. func<int>(1);
  148. }
  149. struct S {
  150. static int n; // expected-note{{declared here}}
  151. int nn; // expected-note 2 {{declared here}}
  152. };
  153. int func_3(int x) {
  154. return x ? S::n :: 0; // expected-error{{'n' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
  155. }
  156. int func_4(int x, S &s) {
  157. return x ? s.nn :: x; // expected-error{{'nn' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
  158. }
  159. int func_5(int x, S &s) {
  160. return x ? s.nn :: S::n; // expected-error{{'nn' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
  161. }
  162. struct S2 {
  163. struct S3;
  164. };
  165. struct S2 :: S3 :: public S2 { // expected-error{{'public' cannot be a part of nested name specifier; did you mean ':'?}}
  166. };
  167. }
  168. namespace InvalidEmptyNames {
  169. // These shouldn't crash, the diagnostics aren't important.
  170. struct ::, struct ::; // expected-error 2 {{expected identifier}} expected-error 2 {{declaration of anonymous struct must be a definition}} expected-warning {{declaration does not declare anything}}
  171. enum ::, enum ::; // expected-error 2 {{expected identifier}} expected-warning {{declaration does not declare anything}}
  172. struct ::__super, struct ::__super; // expected-error 2 {{expected identifier}} expected-error 2 {{expected '::' after '__super'}}
  173. struct ::template foo, struct ::template bar; // expected-error 2 {{expected identifier}} expected-error 2 {{declaration of anonymous struct must be a definition}} expected-warning {{declaration does not declare anything}}
  174. struct ::foo struct::; // expected-error {{no struct named 'foo' in the global namespace}} expected-error {{expected identifier}} expected-error {{declaration of anonymous struct must be a definition}}
  175. class :: : {} a; // expected-error {{expected identifier}} expected-error {{expected class name}}
  176. }