Skip to content

Commit 91d1c50

Browse files
compilersupport: fix compilation in C23 mode
GCC15 added support for C23's `unreachable()`, causing a warning: ``` src/compilersupport_p.h:215:11: warning: ‘unreachable’ redefined 215 | # define unreachable() __builtin_unreachable() | ^~~~~~~~~~~ stddef.h:468:9: note: this is the previous definition 468 | #define unreachable() (__builtin_unreachable ()) | ^~~~~~~~~~~ ``` Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
1 parent 0cd8b05 commit 91d1c50

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

src/compilersupport_p.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,10 @@
5252
# define cbor_static_assert(x) ((void)sizeof(char[2*!!(x) - 1]))
5353
#endif
5454

55-
#if defined(__has_cpp_attribute) && defined(__cplusplus) // C++17
55+
#if defined(__has_cpp_attribute) // C23 and C++17
5656
# if __has_cpp_attribute(fallthrough)
5757
# define CBOR_FALLTHROUGH [[fallthrough]]
5858
# endif
59-
#elif defined(__has_c_attribute) && !defined(__cplusplus) // C23
60-
# if __has_c_attribute(fallthrough)
61-
# define CBOR_FALLTHROUGH [[fallthrough]]
62-
# endif
6359
#endif
6460
#ifndef CBOR_FALLTHROUGH
6561
# ifdef __GNUC__
@@ -213,22 +209,22 @@
213209
# define CBOR_NULLPTR NULL
214210
#endif
215211

216-
#ifdef __GNUC__
217-
#ifndef likely
212+
#ifdef likely
213+
/* something has already defined likely(), accept it */
214+
#elif defined(__GNUC__)
218215
# define likely(x) __builtin_expect(!!(x), 1)
219-
#endif
220-
#ifndef unlikely
221216
# define unlikely(x) __builtin_expect(!!(x), 0)
217+
#else
218+
# define likely(x) (x)
219+
# define unlikely(x) (x)
222220
#endif
221+
222+
#ifdef unreachable
223+
/* C23 has unreachable() */
224+
#elif defined(__GNUC__)
223225
# define unreachable() __builtin_unreachable()
224226
#elif defined(_MSC_VER)
225-
# define likely(x) (x)
226-
# define unlikely(x) (x)
227227
# define unreachable() __assume(0)
228-
#else
229-
# define likely(x) (x)
230-
# define unlikely(x) (x)
231-
# define unreachable() do {} while (0)
232228
#endif
233229

234230
static inline bool add_check_overflow(size_t v1, size_t v2, size_t *r)

0 commit comments

Comments
 (0)