Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ template <typename T> constexpr auto max_of(T a, T b) -> T {
return a > b ? a : b;
}

FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
const char* message);

namespace detail {
// Suppresses "unused variable" warnings with the method described in
// https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/.
Expand Down Expand Up @@ -388,7 +391,7 @@ FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
# define FMT_ASSERT(condition, message) \
((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \
? (void)0 \
: fmt::detail::assert_fail(__FILE__, __LINE__, (message)))
: ::fmt::assert_fail(__FILE__, __LINE__, (message)))
#endif

#ifdef FMT_USE_INT128
Expand Down
10 changes: 9 additions & 1 deletion include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@
#endif

FMT_BEGIN_NAMESPACE
namespace detail {

#ifndef FMT_CUSTOM_ASSERT_FAIL
FMT_FUNC void assert_fail(const char* file, int line, const char* message) {
// Use unchecked std::fprintf to avoid triggering another assertion when
// writing to stderr fails.
fprintf(stderr, "%s:%d: assertion failed: %s", file, line, message);
abort();
}
#endif

namespace detail {

// For binary compatibility.
FMT_FUNC void assert_fail(const char* file, int line, const char* message) {
::fmt::assert_fail(file, line, message);
}

FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code,
string_view message) noexcept {
Expand Down
3 changes: 1 addition & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ template <typename T> struct iterator_traits<fmt::basic_appender<T>> {
#elif FMT_USE_EXCEPTIONS
# define FMT_THROW(x) throw x
#else
# define FMT_THROW(x) \
::fmt::detail::assert_fail(__FILE__, __LINE__, (x).what())
# define FMT_THROW(x) ::fmt::assert_fail(__FILE__, __LINE__, (x).what())
#endif

// Defining FMT_REDUCE_INT_INSTANTIATIONS to 1, will reduce the number of
Expand Down
Loading