_Noreturn.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* A C macro for declaring that a function does not return.
  2. Copyright (C) 2011-2023 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify it
  4. under the terms of the GNU Lesser General Public License as published
  5. by the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  13. #ifndef _Noreturn
  14. # if (defined __cplusplus \
  15. && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
  16. || (defined _MSC_VER && 1900 <= _MSC_VER)) \
  17. && 0)
  18. /* [[noreturn]] is not practically usable, because with it the syntax
  19. extern _Noreturn void func (...);
  20. would not be valid; such a declaration would only be valid with 'extern'
  21. and '_Noreturn' swapped, or without the 'extern' keyword. However, some
  22. AIX system header files and several gnulib header files use precisely
  23. this syntax with 'extern'. */
  24. # define _Noreturn [[noreturn]]
  25. # elif ((!defined __cplusplus || defined __clang__) \
  26. && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
  27. || (!defined __STRICT_ANSI__ \
  28. && (4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
  29. || (defined __apple_build_version__ \
  30. ? 6000000 <= __apple_build_version__ \
  31. : 3 < __clang_major__ + (5 <= __clang_minor__))))))
  32. /* _Noreturn works as-is. */
  33. # elif (2 < __GNUC__ + (8 <= __GNUC_MINOR__) || defined __clang__ \
  34. || 0x5110 <= __SUNPRO_C)
  35. # define _Noreturn __attribute__ ((__noreturn__))
  36. # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
  37. # define _Noreturn __declspec (noreturn)
  38. # else
  39. # define _Noreturn
  40. # endif
  41. #endif