rework attribute definitions in atrb.h

This commit is contained in:
2025-06-12 10:50:07 +02:00
parent 09ee136177
commit cad49f2912

View File

@@ -2,8 +2,22 @@
// Licensed under the MIT Licence. See LICENSE for details // Licensed under the MIT Licence. See LICENSE for details
#pragma once #pragma once
// define the attributes where possible
// default attribute definitions (empty) #if defined(__GNUC__) || defined(__clang__)
#define atrb(...) __attribute__(__VA_ARGS__)
#define atrb_deprecated __attribute__((depricated))
#define atrb_unused __attribute__((unused))
#define atrb_pure __attribute__((pure))
#define atrb_const __attribute__((const))
#define atrb_noreturn __attribute__((noreturn))
#define atrb_format(...) __attribute__((format(__VA_ARGS__)))
#define atrb_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
#elif defined(_MSC_VER)
#define atrb __declspec
#define atrb_deprecated __declspec(deprecated)
#define atrb_noreturn __declspec(noreturn)
#else
#define atrb
#define atrb_deprecated #define atrb_deprecated
#define atrb_unused #define atrb_unused
#define atrb_pure #define atrb_pure
@@ -11,45 +25,4 @@
#define atrb_noreturn #define atrb_noreturn
#define atrb_format() #define atrb_format()
#define atrb_nonnull() #define atrb_nonnull()
// define the attributes where possible
#if defined(__GNUC__) || defined(__clang__)
#if __has_attribute(deprecated)
#undef atrb_deprecated
#define atrb_deprecated __attribute__((deprecated))
#endif
#if __has_attribute(unused)
#undef atrb_unused
#define atrb_unused __attribute__((unused))
#endif
#if __has_attribute(pure)
#undef atrb_pure
#define atrb_pure __attribute__((pure))
#endif
#if __has_attribute(const)
#undef atrb_const
#define atrb_const __attribute__((const))
#endif
#if __has_attribute(noreturn)
#undef atrb_noreturn
#define atrb_noreturn __attribute__((noreturn))
#endif
#if __has_attribute(format)
#undef atrb_format
#define atrb_format(...) __attribute__((format(__VA_ARGS__)))
#endif
#if __has_attribute(nonnull)
#undef atrb_nonnull
#define atrb_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
#endif
#elif defined(_MSC_VER)
#undef atrb_depatrb_deprecated
#define atrb_deprecated __declspec(deprecated)
#endif #endif