warn-shadow.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s
  2. int i; // expected-note 3 {{previous declaration is here}}
  3. void foo() {
  4. int pass1;
  5. int i; // expected-warning {{declaration shadows a variable in the global scope}} \
  6. // expected-note {{previous declaration is here}}
  7. {
  8. int pass2;
  9. int i; // expected-warning {{declaration shadows a local variable}} \
  10. // expected-note {{previous declaration is here}}
  11. {
  12. int pass3;
  13. int i; // expected-warning {{declaration shadows a local variable}}
  14. }
  15. }
  16. int sin; // okay; 'sin' has not been declared, even though it's a builtin.
  17. }
  18. // <rdar://problem/7677531>
  19. void (^test1)(int) = ^(int i) { // expected-warning {{declaration shadows a variable in the global scope}} \
  20. // expected-note{{previous declaration is here}}
  21. {
  22. int i; // expected-warning {{declaration shadows a local variable}} \
  23. // expected-note{{previous declaration is here}}
  24. (^(int i) { return i; })(i); //expected-warning {{declaration shadows a local variable}}
  25. }
  26. };
  27. struct test2 {
  28. int i;
  29. };
  30. void test3(void) {
  31. struct test4 {
  32. int i;
  33. };
  34. }
  35. void test4(int i) { // expected-warning {{declaration shadows a variable in the global scope}}
  36. }
  37. // Don't warn about shadowing for function declarations.
  38. void test5(int i);
  39. void test6(void (*f)(int i)) {}
  40. void test7(void *context, void (*callback)(void *context)) {}
  41. extern int bob; // expected-note {{previous declaration is here}}
  42. // rdar://8883302
  43. void rdar8883302() {
  44. extern int bob; // don't warn for shadowing.
  45. }
  46. void test8() {
  47. int bob; // expected-warning {{declaration shadows a variable in the global scope}}
  48. }