Use musttail attribute to guarantee tail recursion (#1849)

This commit is contained in:
Rangi
2025-10-20 15:56:22 -04:00
committed by GitHub
parent 1badba03d8
commit 2873e0b8c8
3 changed files with 25 additions and 9 deletions

View File

@@ -60,4 +60,13 @@
#define _POSIX_C_SOURCE 200809L
#endif
// gcc and clang have their own `musttail` attributes for tail recursion
#if defined(__clang__) && __has_cpp_attribute(clang::musttail)
#define MUSTTAIL [[clang::musttail]]
#elif defined(__GNUC__) && __has_cpp_attribute(gnu::musttail)
#define MUSTTAIL [[gnu::musttail]]
#else
#define MUSTTAIL
#endif
#endif // RGBDS_PLATFORM_HPP