unreachable.h 1010 B

1234567891011121314151617181920212223242526272829303132333435
  1. /// @file
  2. /// @ingroup cgraph_utils
  3. #pragma once
  4. #include <assert.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. /** Marker for a point in code which execution can never reach.
  8. *
  9. * As a C11 function, this could be thought of as:
  10. *
  11. * _Noreturn void UNREACHABLE(void);
  12. *
  13. * This can be used to explain that a switch is exhaustive:
  14. *
  15. * switch (…) {
  16. * default: UNREACHABLE();
  17. * …remaining cases that cover all possibilities…
  18. * }
  19. *
  20. * or that a function coda can be omitted:
  21. *
  22. * int foo(void) {
  23. * while (always_true()) {
  24. * }
  25. * UNREACHABLE();
  26. * }
  27. */
  28. #define UNREACHABLE() \
  29. do { \
  30. fprintf(stderr, "%s:%d: claimed unreachable code was reached\n", __FILE__, \
  31. __LINE__); \
  32. abort(); \
  33. } while (0)