Commit Graph

1839 Commits

Author SHA1 Message Date
Kefu Chai
274ba2645b
allow format_as() to format reference (#3739)
before this change, format_as() is unable to format a type which
has `auto format_as() -> const another_type&`, and `another_type`
is formattable. because `format_as_result` maps the result type
as it is, and the compiler refuses to compile
`static_cast<T*>(nullptr)`, where T is a reference type. but
it would be handy if we could use `format_as()` to format types
which, for instance, owns / inherit from a formattable type, and
delegate the formatter to these variables instead without creating
a copy of them.

in this change:

* instruct `format_as_result` to map the
  result type to the decayed type, so that `type` can be the decayed
  type of result type, and this also enables `type` to be formattable,
  as long as the decayed type is formattable.
* corresponding test is added to format-test.cc

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
2023-12-10 08:49:53 -08:00
Victor Zverovich
9048add999 Report out-of-range errors in chrono 2023-12-10 08:28:50 -08:00
Ikko Eltociear Ashimine
9a6fd11a56
Fix typo in gmock-gtest-all.cc (#3747)
syntetic -> synthetic
2023-12-09 08:13:20 -08:00
js324
573d74395b
error on bool arg w/ char pres_type (#3734) 2023-12-05 13:45:10 -08:00
Victor Zverovich
5d55375a8a Experiment with scan buffering 2023-12-03 08:09:36 -08:00
Ivan Shapovalov
71bd51e6c2
Implement %j specifier for std::chrono::duration (#3732)
This adds support for `%j` presentation type for duration types:

> "If the type being formatted is a specialization of duration, the decimal
number of days without padding."

Fixes #3643.
2023-12-03 07:29:58 -08:00
Victor Zverovich
f575089243 Simplify test 2023-12-01 08:52:42 -08:00
Félix-Antoine Constantin
99b9fbf8ef
Add formatter for std::source_location (#3730) 2023-11-30 10:05:56 -08:00
Victor Zverovich
04718008ab Minor cleanup 2023-11-30 07:43:31 -08:00
js324
b87ea22e29
Add native and generic representation for filesystem::path format spec (#3729) 2023-11-29 14:49:36 -08:00
Victor Zverovich
5cfd28d476 Experiment with FILE in scan 2023-11-26 10:01:42 -08:00
Corentin Schreiber
7f8d419115
Fix overflow in time_point formatting with large dates (#3727)
* Fix #3725 and rename fmt_safe_duration_cast to fmt_duration_cast
The function is now more generic and will handle all casts. It also
takes care of toggling safe vs unsafe casts using
FMT_SAFE_DURATION_CAST.

* Refactor fmt_duration_cast to put #ifdef inside the function

* Fix compilation error with FMT_USE_LOCAL_TIME
2023-11-25 08:36:55 -08:00
Victor Zverovich
ccc9ab7bf9 Include correct header 2023-11-25 08:23:41 -08:00
Victor Zverovich
c4283ec471 Fix a libc++ warning and move the test to the right place 2023-11-25 08:20:53 -08:00
Victor Zverovich
c3f9a73445 Apply coding conventions 2023-11-25 07:43:44 -08:00
Victor Zverovich
ffa5b14fe3 Make gtest-extra-test more portable 2023-11-24 10:09:21 -08:00
Victor Zverovich
bea7ecc710 Disable locale-specific tests on OpenBSD 2023-11-24 09:45:56 -08:00
Victor Zverovich
8a39388516 Fix the default locale in ostream_formatter 2023-11-24 09:24:43 -08:00
Victor Zverovich
c13753a70c Fix handling of invalid Unicode in precision 2023-11-18 08:36:11 -10:00
Ole Bøe
864a8b5f38
fix: support optional<T> with format_as(T) (#3713)
Formatting a std::optional<T> where T had a custom format_as(T) function failed to compile with clang,
due to set_debug_format being hidden by private inheritance. This fix makes the function available through a using clause.
2023-11-16 15:02:33 -08:00
Victor Zverovich
649fe0fc8b Fix handling of null strings with the s specifier 2023-11-15 17:03:01 -10:00
Victor Zverovich
19276d7325 Fix an inconsistentcy between to_string and format 2023-10-28 08:05:11 -07:00
June Liu
2ac6c5ca8b
Fix error C2668 on Windows with option /std:c++latest (#3680)
* Namespace-qualify to avoid ambiguity with std::format_to for format-test.cc

When build fmt with MSVC under option /std:c++latest, it failed due to `error 2668: 'std::format_to': ambiguous call to overloaded function`, so add namespace to qualify the call to format_to to avoid this issue.
2023-10-16 09:54:02 -07:00
Victor Zverovich
130cf54cbc Use a more sensible locale in tests 2023-10-08 10:49:21 -07:00
Victor Zverovich
8e0ca0589f Use a more sensible locale in tests 2023-10-08 09:21:02 -07:00
Victor Zverovich
bf497ac068 Cleanup test 2023-10-08 07:30:08 -07:00
Richard Kellnberger
bb8d50f04b
add a suffix for days and fix the one for minutes (#3664) 2023-10-07 12:45:34 -07:00
Giel van Schijndel
f76603f21e
fix: make std::bitset formattable again (#3660)
* fix: make std::bitset formattable again

It used to be formattable via operator<<(ostream&) implicitly. Make it
formattable again, but this time via formatter specialization.

* fix: make nested_formatter constexpr default constructible
2023-10-03 09:53:47 -07:00
Vladislav Shchapov
492a99c964
Fix error: 'char_traits<custom_char>' is deprecated: char_traits<T> for T not equal to char, wchar_t, char8_t, char16_t or char32_t is non-standard and is provided for a temporary period. It will be removed in LLVM 18, so please migrate off of it. [-Werror,-Wdeprecated-declarations] (#3634)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
2023-09-18 15:46:17 -07:00
Victor Zverovich
0e01e46c11 Implement nested formatter 2023-09-18 14:21:21 -07:00
Dana Jansens
f6ca4ea199
Avoid a space in the UDL definition (#3610)
* Avoid a space in the UDL definition except on GCC before 4.9

Clang 18 has grown a warning about the space being deprecated which
is enabled by default in their nightly binaries. However GCC before 4.9
will reject the UDL definition unless there is a space there, so we need
to keep the space conditionally for it.

* Remove UDLs on GCC before 4.9 to simplify things

GCC before 4.9 rejects the syntax that is now
rejected on more modern compilers.

* Disable compile-error-test on GCC < 4.9

This avoids the UDL tests failing as GCC < 4.9 can not parse UDLs
without a space, but the space is malformed in modern compilers.
2023-09-18 08:09:42 -07:00
Gleb Mazovetskiy
a8a73da7e4
Add an option to avoid wchar APIs on Windows (#3636)
With this, fmt can be used on Windows 98 and the Original Xbox with:

    set(FMT_OS OFF)

It is not exposed as a CMake option but one can define it manually
in the fmt subproject, e.g.:

    target_compile_definitions(fmt PUBLIC FMT_WINDOWS_NO_WCHAR)

Fixes #3631
2023-09-17 08:49:51 -07:00
Vladislav Shchapov
016b1faede
Fix symbol leak (#3627)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
2023-09-16 07:26:36 -07:00
Victor Zverovich
d4987546a4 Add an experimental nested formatter 2023-09-10 11:56:55 -07:00
Victor Zverovich
ca608547e5 Workaround a C++11 issue 2023-09-04 10:07:14 -07:00
Victor Zverovich
a79a979828 Cleanup ranges test 2023-09-04 09:19:40 -07:00
Victor Zverovich
457bb6a98f Merge the copyright comment since there are many contributors 2023-09-04 09:09:01 -07:00
Alex Guteniev
9b74160817
atomic_flag formatting (#3594) 2023-08-25 08:06:10 -07:00
Ben Deane
6c845f57e5
Fix formatted_size with FMT_COMPILE and format specs (#3588)
Addresses issue #3586
2023-08-15 06:45:48 -07:00
Zhanwei Wang
5a866fe852
Add formatter for std::atomic (#3574) 2023-08-14 08:34:31 -07:00
Vladislav Shchapov
e150ea0cc2 to_string supports types with format_as
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
2023-08-13 08:39:52 -07:00
Victor Zverovich
d424862319 Fix fixed precision handling during rounding in long double 2023-08-07 13:56:53 -07:00
Vladislav Shchapov
aeb6ad4dd0
Added formatter for bit_reference-like types (#3570)
* Add test for std::vector<bool>::reference

Co-authored-by: Felix <felix-antoine.constantin@polymtl.ca>
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>

* Add test for std::bitset<N>::reference

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>

* Add test for const std::bitset<N>::reference and const std::vector<bool>::reference

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>

* Add bit_reference-like formatter

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>

* Use std::addressof

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>

---------

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
Co-authored-by: Felix <felix-antoine.constantin@polymtl.ca>
2023-08-06 11:36:30 -07:00
5chmidti
8a4bec5cf5
fix ambiguous formatter lookup for flat_set (#3561) 2023-07-31 09:26:33 -07:00
Victor Zverovich
3dec65b7fd Use replacement character in path 2023-07-22 09:07:28 -07:00
Victor Zverovich
ac0ab8eff3 Improve path formatter 2023-07-20 17:49:12 -07:00
Victor Zverovich
e475859042 Fix overspecified tests 2023-07-20 14:09:22 -07:00
Victor Zverovich
436c131d4c Optimize compiled format_to_n 2023-07-20 12:35:01 -07:00
Victor Zverovich
388bc296b7 Fix fixed formatting of small long doubles 2023-07-20 12:06:05 -07:00
Victor Zverovich
9bea6ec04a Don't use deprecated checked_array_iterator 2023-07-20 07:12:06 -07:00