statements.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code
  2. void test1() {
  3. { ; { ;;}} ;;
  4. }
  5. void test2() {
  6. if (0) { if (1) {} } else { }
  7. do { } while (0);
  8. while (0) while(0) do ; while(0);
  9. for ((void)0;0;(void)0)
  10. for (;;)
  11. for ((void)9;0;(void)2)
  12. ;
  13. for (int X = 0; 0; (void)0);
  14. }
  15. void test3() {
  16. switch (0) {
  17. case 4:
  18. if (0) {
  19. case 6: ;
  20. }
  21. default:
  22. ;
  23. }
  24. }
  25. void test4() {
  26. if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}}
  27. int X; // declaration in a block.
  28. foo: if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}}
  29. }
  30. typedef int t;
  31. void test5() {
  32. if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}}
  33. t x = 0;
  34. if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}}
  35. }
  36. void test6(void) {
  37. do
  38. . // expected-error {{expected expression}}
  39. while (0);
  40. }
  41. int test7() {
  42. return 4 // expected-error {{expected ';' after return statement}}
  43. }
  44. void test8() {
  45. // Should not skip '}' and produce a "expected '}'" error.
  46. undecl // expected-error {{use of undeclared identifier 'undecl'}}
  47. }
  48. int test9() {
  49. int T[] = {1, 2, };
  50. int X;
  51. X = 0, // expected-error {{expected ';' after expression}}
  52. {
  53. }
  54. X = 0, // expected-error {{expected ';' after expression}}
  55. if (0)
  56. ;
  57. return 4, // expected-error {{expected ';' after return statement}}
  58. }