constexpr-addr-of-static.c 847 B

12345678910111213141516171819202122232425262728293031323334353637
  1. static int a = 1;
  2. static int b[2] = {1, 1};
  3. static void c(void) {}
  4. static int *d = &a; // OK
  5. static int *e = d; // KO
  6. static int *f = b; // OK
  7. static void (*g)(void) = c; // OK
  8. static void (*h)(void) = &c; // OK
  9. static int *i = &*&a; // OK
  10. static int *j = &*b; // OK
  11. static int *k = &*d; // KO
  12. static void l(void) {
  13. int a = 1;
  14. static int *b = &a; // KO
  15. }
  16. static void m(void) {
  17. static int a = 1;
  18. static int *b = &a; // OK
  19. }
  20. /*
  21. * check-name: constexpr static object address
  22. * check-command: sparse -Wconstexpr-not-const $file
  23. *
  24. * check-error-start
  25. constexpr-addr-of-static.c:6:17: warning: non-constant initializer for static object
  26. constexpr-addr-of-static.c:14:19: warning: non-constant initializer for static object
  27. constexpr-addr-of-static.c:19:26: warning: non-constant initializer for static object
  28. * check-error-end
  29. */