Skip to content

Commit

Permalink
Merge branch 'fmtlib:master' into zig-pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Sep 17, 2023
2 parents 63d6a99 + aa3c5a4 commit 826b2e3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
14 changes: 7 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Examples
.. code:: c++

#include <fmt/core.h>

int main() {
fmt::print("Hello, world!\n");
}
Expand Down Expand Up @@ -294,7 +294,7 @@ Then you can run the speed test::
or the bloat test::

$ make bloat-test

Migrating code
--------------

Expand All @@ -315,13 +315,13 @@ Projects using this library
an open-source library for mathematical programming

* `Aseprite <https://github.com/aseprite/aseprite>`_:
animated sprite editor & pixel art tool
animated sprite editor & pixel art tool

* `AvioBook <https://www.aviobook.aero/en>`_: a comprehensive aircraft
operations suite

* `Blizzard Battle.net <https://battle.net/>`_: an online gaming platform

* `Celestia <https://celestia.space/>`_: real-time 3D visualization of space

* `Ceph <https://ceph.com/>`_: a scalable distributed storage system
Expand All @@ -330,7 +330,7 @@ Projects using this library

* `ClickHouse <https://github.com/ClickHouse/ClickHouse>`_: an analytical database
management system

* `Contour <https://github.com/contour-terminal/contour/>`_: a modern terminal emulator

* `CUAUV <https://cuauv.org/>`_: Cornell University's autonomous underwater
Expand Down Expand Up @@ -391,7 +391,7 @@ Projects using this library

* `quasardb <https://www.quasardb.net/>`_: a distributed, high-performance,
associative database

* `Quill <https://github.com/odygrd/quill>`_: asynchronous low-latency logging library

* `QKW <https://github.com/ravijanjam/qkw>`_: generalizing aliasing to simplify
Expand Down
4 changes: 4 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ checked at compile time in C++20. To pass a runtime format string wrap it in

*args* is an argument list representing objects to be formatted.

I/O errors are reported as `std::system_error
<https://en.cppreference.com/w/cpp/error/system_error>`_ exceptions unless
specified otherwise.

.. _format:

.. doxygenfunction:: format(format_string<T...> fmt, T&&... args) -> std::string
Expand Down
20 changes: 11 additions & 9 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,20 @@
# define FMT_END_EXPORT
#endif

#if FMT_GCC_VERSION || FMT_CLANG_VERSION
# define FMT_VISIBILITY(value) __attribute__((visibility(value)))
#else
# define FMT_VISIBILITY(value)
#endif

#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
# ifdef FMT_LIB_EXPORT
# if defined(FMT_LIB_EXPORT)
# define FMT_API __declspec(dllexport)
# elif defined(FMT_SHARED)
# define FMT_API __declspec(dllimport)
# endif
#else
# if defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)
# if defined(__GNUC__) || defined(__clang__)
# define FMT_API __attribute__((visibility("default")))
# endif
# endif
#elif defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)
# define FMT_API FMT_VISIBILITY("default")
#endif
#ifndef FMT_API
# define FMT_API
Expand Down Expand Up @@ -2541,8 +2543,8 @@ FMT_CONSTEXPR auto parse_format_specs(ParseContext& ctx)
decltype(arg_mapper<context>().map(std::declval<const T&>())),
typename strip_named_arg<T>::type>;
#if defined(__cpp_if_constexpr)
if constexpr (std::is_default_constructible_v<
formatter<mapped_type, char_type>>) {
if constexpr (std::is_default_constructible<
formatter<mapped_type, char_type>>::value) {
return formatter<mapped_type, char_type>().parse(ctx);
} else {
type_is_unformattable_for<T, char_type> _;
Expand Down
9 changes: 5 additions & 4 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@
# define FMT_NO_UNIQUE_ADDRESS
#endif

#if FMT_GCC_VERSION || defined(__clang__)
# define FMT_VISIBILITY(value) __attribute__((visibility(value)))
// Visibility when compiled as a shared library/object.
#if defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)
# define FMT_SO_VISIBILITY(value) FMT_VISIBILITY(value)
#else
# define FMT_VISIBILITY(value)
# define FMT_SO_VISIBILITY(value)
#endif

#ifdef __has_builtin
Expand Down Expand Up @@ -1046,7 +1047,7 @@ FMT_BEGIN_EXPORT
#endif

/** An error reported from a formatting function. */
class FMT_VISIBILITY("default") format_error : public std::runtime_error {
class FMT_SO_VISIBILITY("default") format_error : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
};
Expand Down
4 changes: 4 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ TEST(memory_buffer_test, max_size_allocator_overflow) {
EXPECT_THROW(buffer.resize(161), std::exception);
}

TEST(format_test, exception_from_lib) {
EXPECT_THROW_MSG(fmt::throw_format_error("test"), format_error, "test");
}

TEST(format_test, escape) {
EXPECT_EQ("{", fmt::format("{{"));
EXPECT_EQ("before {", fmt::format("before {{"));
Expand Down

0 comments on commit 826b2e3

Please sign in to comment.