History

osdep/compiler: use C23 attributes if available

Kacper Michajłow committed 1 year ago

Commit 16bbfbf1 parent 7f1e2681 file · +15 −6Browse files

Unified · Split

osdep/compiler.h+15−6
@@ -3,21 +3,30 @@ · 2 unmodified lines
33
44 #define MP_EXPAND_ARGS(...) __VA_ARGS__
55
6−#if defined(__GNUC__) || defined(__clang__)
7−#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format(printf, a1, a2)))
8−#define SCANF_ATTRIBUTE(a1, a2) __attribute__ ((format(scanf, a1, a2)))
6+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
7+#define MP_NORETURN [[noreturn]]
8+#define MP_FALLTHROUGH [[fallthrough]]
9+#define MP_WARN_UNUSED_RESULT [[nodiscard]]
10+#define MP_UNUSED [[maybe_unused]]
11+#elif defined(__GNUC__) || defined(__clang__)
912 #define MP_NORETURN __attribute__((noreturn))
1013 #define MP_FALLTHROUGH __attribute__((fallthrough))
1114 #define MP_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
1215 #define MP_UNUSED __attribute__((unused))
13−#define MP_ASSERT_UNREACHABLE() (assert(!"unreachable"), __builtin_unreachable())
1416 #else
15−#define PRINTF_ATTRIBUTE(a1, a2)
16−#define SCANF_ATTRIBUTE(a1, a2)
1717 #define MP_NORETURN
1818 #define MP_FALLTHROUGH do {} while (0)
1919 #define MP_WARN_UNUSED_RESULT
2020 #define MP_UNUSED
21+#endif
22+
23+#if defined(__GNUC__) || defined(__clang__)
24+#define PRINTF_ATTRIBUTE(a1, a2) __attribute__((format(printf, a1, a2)))
25+#define SCANF_ATTRIBUTE(a1, a2) __attribute__((format(scanf, a1, a2)))
26+#define MP_ASSERT_UNREACHABLE() (assert(!"unreachable"), __builtin_unreachable())
27+#else
28+#define PRINTF_ATTRIBUTE(a1, a2)
29+#define SCANF_ATTRIBUTE(a1, a2)
2130 #define MP_ASSERT_UNREACHABLE() (assert(!"unreachable"), abort())
2231 #endif
2332

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t