From 2f9acd18380cf80ce212bd2869364d4f36d783fb Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 29 Nov 2019 08:04:47 -0800 Subject: [PATCH] Remove dependency on --- include/fmt/color.h | 6 +++--- include/fmt/core.h | 17 ++++++++++++----- include/fmt/format-inl.h | 8 ++++++-- include/fmt/format.h | 4 +++- test/format | 1 + 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/include/fmt/color.h b/include/fmt/color.h index 8de5b294..362a95e1 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -299,15 +299,15 @@ class text_style { return static_cast(ems) != 0; } FMT_CONSTEXPR internal::color_type get_foreground() const FMT_NOEXCEPT { - assert(has_foreground() && "no foreground specified for this style"); + FMT_ASSERT(has_foreground(), "no foreground specified for this style"); return foreground_color; } FMT_CONSTEXPR internal::color_type get_background() const FMT_NOEXCEPT { - assert(has_background() && "no background specified for this style"); + FMT_ASSERT(has_background(), "no background specified for this style"); return background_color; } FMT_CONSTEXPR emphasis get_emphasis() const FMT_NOEXCEPT { - assert(has_emphasis() && "no emphasis specified for this style"); + FMT_ASSERT(has_emphasis(), "no emphasis specified for this style"); return ems; } diff --git a/include/fmt/core.h b/include/fmt/core.h index 80869b82..346f7616 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -8,7 +8,6 @@ #ifndef FMT_CORE_H_ #define FMT_CORE_H_ -#include #include // std::FILE #include #include @@ -187,10 +186,6 @@ # define FMT_EXTERN #endif -#ifndef FMT_ASSERT -# define FMT_ASSERT(condition, message) assert((condition) && (message)) -#endif - // libc++ supports string_view in pre-c++17. #if (FMT_HAS_INCLUDE() && \ (__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \ @@ -229,6 +224,18 @@ namespace internal { // A workaround for gcc 4.8 to make void_t work in a SFINAE context. template struct void_t_impl { using type = void; }; +void assert_fail(const char* file, int line, const char* message); + +#ifndef FMT_ASSERT +# ifdef NDEBUG +# define FMT_ASSERT(condition, message) +# else +# define FMT_ASSERT(condition, message) \ + if (!(condition)) \ + fmt::internal::assert_fail(__FILE__, __LINE__, (message)) +# endif +#endif + #if defined(FMT_USE_STRING_VIEW) template using std_string_view = std::basic_string_view; #elif defined(FMT_USE_EXPERIMENTAL_STRING_VIEW) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 9c8e0816..99ad5528 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -10,8 +10,7 @@ #include "format.h" -#include - +#include #include #include #include @@ -57,6 +56,11 @@ inline fmt::internal::null<> strerror_s(char*, std::size_t, ...) { return {}; } FMT_BEGIN_NAMESPACE namespace internal { +FMT_FUNC void assert_fail(const char* file, int line, const char* message) { + print(stderr, "{}:{}: assertion failed: {}", file, line, message); + std::abort(); +} + #ifndef _MSC_VER # define FMT_SNPRINTF snprintf #else // _MSC_VER diff --git a/include/fmt/format.h b/include/fmt/format.h index 3a48f21f..76c5ea9d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -220,7 +220,9 @@ inline Dest bit_cast(const Source& source) { inline bool is_big_endian() { auto u = 1u; - struct bytes { char data[sizeof(u)]; }; + struct bytes { + char data[sizeof(u)]; + }; return bit_cast(u).data[0] == 0; } diff --git a/test/format b/test/format index d110f3ec..db27614e 100644 --- a/test/format +++ b/test/format @@ -8,6 +8,7 @@ #ifndef FMT_FORMAT_ #define FMT_FORMAT_ +#include #include #include "fmt/format.h"