captured-statements.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
  2. void test_gotos() {
  3. goto L1; // expected-error {{use of undeclared label 'L1'}}
  4. goto L3; // OK
  5. #pragma clang __debug captured
  6. {
  7. L1:
  8. goto L2; // OK
  9. L2:
  10. goto L3; // expected-error {{use of undeclared label 'L3'}}
  11. }
  12. L3: ;
  13. }
  14. void test_break_continue() {
  15. while (1) {
  16. #pragma clang __debug captured
  17. {
  18. break; // expected-error {{'break' statement not in loop or switch statement}}
  19. continue; // expected-error {{'continue' statement not in loop statement}}
  20. }
  21. }
  22. }
  23. void test_return() {
  24. while (1) {
  25. #pragma clang __debug captured
  26. {
  27. return; // expected-error {{cannot return from default captured statement}}
  28. }
  29. }
  30. }
  31. void test_nest() {
  32. int x;
  33. #pragma clang __debug captured
  34. {
  35. int y;
  36. #pragma clang __debug captured
  37. {
  38. int z;
  39. #pragma clang __debug captured
  40. {
  41. x = z = y; // OK
  42. }
  43. }
  44. }
  45. }
  46. void test_nest_block() {
  47. __block int x; // expected-note {{'x' declared here}}
  48. int y;
  49. ^{
  50. int z;
  51. #pragma clang __debug captured
  52. {
  53. x = y; // expected-error{{__block variable 'x' cannot be captured in a captured statement}}
  54. y = z; // expected-error{{variable is not assignable (missing __block type specifier)}}
  55. z = y; // OK
  56. }
  57. }();
  58. __block int a; // expected-note 2 {{'a' declared here}}
  59. int b;
  60. #pragma clang __debug captured
  61. {
  62. __block int c;
  63. int d;
  64. ^{
  65. a = b; // expected-error{{__block variable 'a' cannot be captured in a captured statement}}
  66. b = d; // OK - Consistent with block inside a lambda
  67. c = a; // expected-error{{__block variable 'a' cannot be captured in a captured statement}}
  68. c = d; // OK
  69. d = b; // expected-error{{variable is not assignable (missing __block type specifier)}}
  70. }();
  71. }
  72. }