TOML_GCC_ATTR => TOML_GNU_ATTR

This commit is contained in:
Mark Gillard 2020-03-22 12:02:56 +02:00
parent f1664fa068
commit 60853e27db
4 changed files with 50 additions and 34 deletions

View File

@ -36,7 +36,7 @@
// macro hygiene // macro hygiene
#if TOML_UNDEF_MACROS #if TOML_UNDEF_MACROS
#undef TOML_USE_STREAMS_FOR_FLOATS #undef TOML_USE_STREAMS_FOR_FLOATS
#undef TOML_GCC_ATTR #undef TOML_GNU_ATTR
#undef TOML_PUSH_WARNINGS #undef TOML_PUSH_WARNINGS
#undef TOML_DISABLE_SWITCH_WARNINGS #undef TOML_DISABLE_SWITCH_WARNINGS
#undef TOML_DISABLE_INIT_WARNINGS #undef TOML_DISABLE_INIT_WARNINGS

View File

@ -64,16 +64,24 @@
#define TOML_DISABLE_INIT_WARNINGS _Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"") #define TOML_DISABLE_INIT_WARNINGS _Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"")
#define TOML_DISABLE_ALL_WARNINGS _Pragma("clang diagnostic ignored \"-Weverything\"") #define TOML_DISABLE_ALL_WARNINGS _Pragma("clang diagnostic ignored \"-Weverything\"")
#define TOML_POP_WARNINGS _Pragma("clang diagnostic pop") #define TOML_POP_WARNINGS _Pragma("clang diagnostic pop")
#define TOML_GCC_ATTR(attr) __attribute__((attr))
#define TOML_ALWAYS_INLINE TOML_GCC_ATTR(__always_inline__) inline
#define TOML_ASSUME(cond) __builtin_assume(cond) #define TOML_ASSUME(cond) __builtin_assume(cond)
#define TOML_UNREACHABLE __builtin_unreachable() #define TOML_UNREACHABLE __builtin_unreachable()
#if defined(_MSC_VER) && defined(__has_declspec_attribute) #if defined(_MSC_VER) // msvc compat mode
#if __has_declspec_attribute(novtable) #if defined(__has_declspec_attribute)
#define TOML_INTERFACE __declspec(novtable) #if __has_declspec_attribute(novtable)
#define TOML_INTERFACE __declspec(novtable)
#endif
#if __has_declspec_attribute(empty_bases)
#define TOML_EMPTY_BASES __declspec(empty_bases)
#endif
#define TOML_ALWAYS_INLINE __forceinline
#endif #endif
#if __has_declspec_attribute(empty_bases) #else // regular ol' clang
#define TOML_EMPTY_BASES __declspec(empty_bases) #define TOML_GNU_ATTR(attr) __attribute__((attr))
#ifdef __has_attribute
#if __has_attribute(always_inline)
#define TOML_ALWAYS_INLINE __attribute__((__always_inline__)) inline
#endif
#endif #endif
#endif #endif
#ifdef __EXCEPTIONS #ifdef __EXCEPTIONS
@ -117,8 +125,8 @@
_Pragma("GCC diagnostic ignored \"-Wchar-subscripts\"") \ _Pragma("GCC diagnostic ignored \"-Wchar-subscripts\"") \
_Pragma("GCC diagnostic ignored \"-Wtype-limits\"") _Pragma("GCC diagnostic ignored \"-Wtype-limits\"")
#define TOML_POP_WARNINGS _Pragma("GCC diagnostic pop") #define TOML_POP_WARNINGS _Pragma("GCC diagnostic pop")
#define TOML_GCC_ATTR(attr) __attribute__((attr)) #define TOML_GNU_ATTR(attr) __attribute__((attr))
#define TOML_ALWAYS_INLINE TOML_GCC_ATTR(__always_inline__) inline #define TOML_ALWAYS_INLINE __attribute__((__always_inline__)) inline
#define TOML_UNREACHABLE __builtin_unreachable() #define TOML_UNREACHABLE __builtin_unreachable()
#if !defined(TOML_RELOPS_REORDERING) && defined(__cpp_impl_three_way_comparison) #if !defined(TOML_RELOPS_REORDERING) && defined(__cpp_impl_three_way_comparison)
#define TOML_RELOPS_REORDERING 1 #define TOML_RELOPS_REORDERING 1
@ -195,8 +203,8 @@
#ifndef TOML_POP_WARNINGS #ifndef TOML_POP_WARNINGS
#define TOML_POP_WARNINGS #define TOML_POP_WARNINGS
#endif #endif
#ifndef TOML_GCC_ATTR #ifndef TOML_GNU_ATTR
#define TOML_GCC_ATTR(attr) #define TOML_GNU_ATTR(attr)
#endif #endif
#ifndef TOML_INTERFACE #ifndef TOML_INTERFACE
#define TOML_INTERFACE #define TOML_INTERFACE
@ -706,18 +714,18 @@ TOML_START
public: public:
TOML_NODISCARD_CTOR TOML_GCC_ATTR(nonnull) TOML_NODISCARD_CTOR TOML_GNU_ATTR(nonnull)
parse_error(const char* desc, source_region&& src) noexcept parse_error(const char* desc, source_region&& src) noexcept
: std::runtime_error{ desc }, : std::runtime_error{ desc },
source_{ std::move(src) } source_{ std::move(src) }
{} {}
TOML_NODISCARD_CTOR TOML_GCC_ATTR(nonnull) TOML_NODISCARD_CTOR TOML_GNU_ATTR(nonnull)
parse_error(const char* desc, const source_region& src) noexcept parse_error(const char* desc, const source_region& src) noexcept
: parse_error{ desc, source_region{ src } } : parse_error{ desc, source_region{ src } }
{} {}
TOML_NODISCARD_CTOR TOML_GCC_ATTR(nonnull) TOML_NODISCARD_CTOR TOML_GNU_ATTR(nonnull)
parse_error(const char* desc, const source_position& position, const source_path_ptr& path = {}) noexcept parse_error(const char* desc, const source_position& position, const source_path_ptr& path = {}) noexcept
: parse_error{ desc, source_region{ position, position, path } } : parse_error{ desc, source_region{ position, position, path } }
{} {}

View File

@ -46,7 +46,7 @@ TOML_IMPL_START
} }
template <typename CHAR> template <typename CHAR>
TOML_GCC_ATTR(nonnull) TOML_ALWAYS_INLINE TOML_GNU_ATTR(nonnull) TOML_ALWAYS_INLINE
void print_to_stream(const char* str, size_t len, std::basic_ostream<CHAR>& stream) TOML_MAY_THROW void print_to_stream(const char* str, size_t len, std::basic_ostream<CHAR>& stream) TOML_MAY_THROW
{ {
static_assert(sizeof(CHAR) == 1); static_assert(sizeof(CHAR) == 1);
@ -64,7 +64,7 @@ TOML_IMPL_START
} }
template <typename CHAR> template <typename CHAR>
TOML_GCC_ATTR(nonnull) TOML_ALWAYS_INLINE TOML_GNU_ATTR(nonnull) TOML_ALWAYS_INLINE
void print_to_stream(const char8_t* str, size_t len, std::basic_ostream<CHAR>& stream) TOML_MAY_THROW void print_to_stream(const char8_t* str, size_t len, std::basic_ostream<CHAR>& stream) TOML_MAY_THROW
{ {
static_assert(sizeof(CHAR) == 1); static_assert(sizeof(CHAR) == 1);

View File

@ -105,16 +105,24 @@
#define TOML_DISABLE_INIT_WARNINGS _Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"") #define TOML_DISABLE_INIT_WARNINGS _Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"")
#define TOML_DISABLE_ALL_WARNINGS _Pragma("clang diagnostic ignored \"-Weverything\"") #define TOML_DISABLE_ALL_WARNINGS _Pragma("clang diagnostic ignored \"-Weverything\"")
#define TOML_POP_WARNINGS _Pragma("clang diagnostic pop") #define TOML_POP_WARNINGS _Pragma("clang diagnostic pop")
#define TOML_GCC_ATTR(attr) __attribute__((attr))
#define TOML_ALWAYS_INLINE TOML_GCC_ATTR(__always_inline__) inline
#define TOML_ASSUME(cond) __builtin_assume(cond) #define TOML_ASSUME(cond) __builtin_assume(cond)
#define TOML_UNREACHABLE __builtin_unreachable() #define TOML_UNREACHABLE __builtin_unreachable()
#if defined(_MSC_VER) && defined(__has_declspec_attribute) #if defined(_MSC_VER) // msvc compat mode
#if __has_declspec_attribute(novtable) #if defined(__has_declspec_attribute)
#define TOML_INTERFACE __declspec(novtable) #if __has_declspec_attribute(novtable)
#define TOML_INTERFACE __declspec(novtable)
#endif
#if __has_declspec_attribute(empty_bases)
#define TOML_EMPTY_BASES __declspec(empty_bases)
#endif
#define TOML_ALWAYS_INLINE __forceinline
#endif #endif
#if __has_declspec_attribute(empty_bases) #else // regular ol' clang
#define TOML_EMPTY_BASES __declspec(empty_bases) #define TOML_GNU_ATTR(attr) __attribute__((attr))
#ifdef __has_attribute
#if __has_attribute(always_inline)
#define TOML_ALWAYS_INLINE __attribute__((__always_inline__)) inline
#endif
#endif #endif
#endif #endif
#ifdef __EXCEPTIONS #ifdef __EXCEPTIONS
@ -158,8 +166,8 @@
_Pragma("GCC diagnostic ignored \"-Wchar-subscripts\"") \ _Pragma("GCC diagnostic ignored \"-Wchar-subscripts\"") \
_Pragma("GCC diagnostic ignored \"-Wtype-limits\"") _Pragma("GCC diagnostic ignored \"-Wtype-limits\"")
#define TOML_POP_WARNINGS _Pragma("GCC diagnostic pop") #define TOML_POP_WARNINGS _Pragma("GCC diagnostic pop")
#define TOML_GCC_ATTR(attr) __attribute__((attr)) #define TOML_GNU_ATTR(attr) __attribute__((attr))
#define TOML_ALWAYS_INLINE TOML_GCC_ATTR(__always_inline__) inline #define TOML_ALWAYS_INLINE __attribute__((__always_inline__)) inline
#define TOML_UNREACHABLE __builtin_unreachable() #define TOML_UNREACHABLE __builtin_unreachable()
#if !defined(TOML_RELOPS_REORDERING) && defined(__cpp_impl_three_way_comparison) #if !defined(TOML_RELOPS_REORDERING) && defined(__cpp_impl_three_way_comparison)
#define TOML_RELOPS_REORDERING 1 #define TOML_RELOPS_REORDERING 1
@ -236,8 +244,8 @@
#ifndef TOML_POP_WARNINGS #ifndef TOML_POP_WARNINGS
#define TOML_POP_WARNINGS #define TOML_POP_WARNINGS
#endif #endif
#ifndef TOML_GCC_ATTR #ifndef TOML_GNU_ATTR
#define TOML_GCC_ATTR(attr) #define TOML_GNU_ATTR(attr)
#endif #endif
#ifndef TOML_INTERFACE #ifndef TOML_INTERFACE
#define TOML_INTERFACE #define TOML_INTERFACE
@ -594,18 +602,18 @@ TOML_START
public: public:
TOML_NODISCARD_CTOR TOML_GCC_ATTR(nonnull) TOML_NODISCARD_CTOR TOML_GNU_ATTR(nonnull)
parse_error(const char* desc, source_region&& src) noexcept parse_error(const char* desc, source_region&& src) noexcept
: std::runtime_error{ desc }, : std::runtime_error{ desc },
source_{ std::move(src) } source_{ std::move(src) }
{} {}
TOML_NODISCARD_CTOR TOML_GCC_ATTR(nonnull) TOML_NODISCARD_CTOR TOML_GNU_ATTR(nonnull)
parse_error(const char* desc, const source_region& src) noexcept parse_error(const char* desc, const source_region& src) noexcept
: parse_error{ desc, source_region{ src } } : parse_error{ desc, source_region{ src } }
{} {}
TOML_NODISCARD_CTOR TOML_GCC_ATTR(nonnull) TOML_NODISCARD_CTOR TOML_GNU_ATTR(nonnull)
parse_error(const char* desc, const source_position& position, const source_path_ptr& path = {}) noexcept parse_error(const char* desc, const source_position& position, const source_path_ptr& path = {}) noexcept
: parse_error{ desc, source_region{ position, position, path } } : parse_error{ desc, source_region{ position, position, path } }
{} {}
@ -1226,7 +1234,7 @@ TOML_IMPL_START
} }
template <typename CHAR> template <typename CHAR>
TOML_GCC_ATTR(nonnull) TOML_ALWAYS_INLINE TOML_GNU_ATTR(nonnull) TOML_ALWAYS_INLINE
void print_to_stream(const char* str, size_t len, std::basic_ostream<CHAR>& stream) TOML_MAY_THROW void print_to_stream(const char* str, size_t len, std::basic_ostream<CHAR>& stream) TOML_MAY_THROW
{ {
static_assert(sizeof(CHAR) == 1); static_assert(sizeof(CHAR) == 1);
@ -1244,7 +1252,7 @@ TOML_IMPL_START
} }
template <typename CHAR> template <typename CHAR>
TOML_GCC_ATTR(nonnull) TOML_ALWAYS_INLINE TOML_GNU_ATTR(nonnull) TOML_ALWAYS_INLINE
void print_to_stream(const char8_t* str, size_t len, std::basic_ostream<CHAR>& stream) TOML_MAY_THROW void print_to_stream(const char8_t* str, size_t len, std::basic_ostream<CHAR>& stream) TOML_MAY_THROW
{ {
static_assert(sizeof(CHAR) == 1); static_assert(sizeof(CHAR) == 1);
@ -9157,7 +9165,7 @@ TOML_END
// macro hygiene // macro hygiene
#if TOML_UNDEF_MACROS #if TOML_UNDEF_MACROS
#undef TOML_USE_STREAMS_FOR_FLOATS #undef TOML_USE_STREAMS_FOR_FLOATS
#undef TOML_GCC_ATTR #undef TOML_GNU_ATTR
#undef TOML_PUSH_WARNINGS #undef TOML_PUSH_WARNINGS
#undef TOML_DISABLE_SWITCH_WARNINGS #undef TOML_DISABLE_SWITCH_WARNINGS
#undef TOML_DISABLE_INIT_WARNINGS #undef TOML_DISABLE_INIT_WARNINGS