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
3 3
4#define MP_EXPAND_ARGS(...) __VA_ARGS__4#define MP_EXPAND_ARGS(...) __VA_ARGS__
5 5
6#if defined(__GNUC__) || defined(__clang__)6#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
7#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format(printf, a1, a2)))7#define MP_NORETURN [[noreturn]]
8#define SCANF_ATTRIBUTE(a1, a2) __attribute__ ((format(scanf, a1, a2)))8#define MP_FALLTHROUGH [[fallthrough]]
9#define MP_WARN_UNUSED_RESULT [[nodiscard]]
10#define MP_UNUSED [[maybe_unused]]
11#elif defined(__GNUC__) || defined(__clang__)
9#define MP_NORETURN __attribute__((noreturn))12#define MP_NORETURN __attribute__((noreturn))
10#define MP_FALLTHROUGH __attribute__((fallthrough))13#define MP_FALLTHROUGH __attribute__((fallthrough))
11#define MP_WARN_UNUSED_RESULT __attribute__((warn_unused_result))14#define MP_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
12#define MP_UNUSED __attribute__((unused))15#define MP_UNUSED __attribute__((unused))
13#define MP_ASSERT_UNREACHABLE() (assert(!"unreachable"), __builtin_unreachable())
14#else16#else
15#define PRINTF_ATTRIBUTE(a1, a2)
16#define SCANF_ATTRIBUTE(a1, a2)
17#define MP_NORETURN17#define MP_NORETURN
18#define MP_FALLTHROUGH do {} while (0)18#define MP_FALLTHROUGH do {} while (0)
19#define MP_WARN_UNUSED_RESULT19#define MP_WARN_UNUSED_RESULT
20#define MP_UNUSED20#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)
21#define MP_ASSERT_UNREACHABLE() (assert(!"unreachable"), abort())30#define MP_ASSERT_UNREACHABLE() (assert(!"unreachable"), abort())
22#endif31#endif
23 32

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