Skip to content

Improve docs: Add compile-time options to API documentation#4551

Merged
vitaut merged 1 commit intofmtlib:masterfrom
teruyamato0731:master
Sep 30, 2025
Merged

Improve docs: Add compile-time options to API documentation#4551
vitaut merged 1 commit intofmtlib:masterfrom
teruyamato0731:master

Conversation

@teruyamato0731
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread include/fmt/chrono.h Outdated
@teruyamato0731
Copy link
Copy Markdown
Contributor Author

@vitaut I'm having trouble with a compilation error in the CI for this PR. I'm not sure how to resolve the build failure on older GCC versions. Could you please take a look when you have a moment?

https://github.com/fmtlib/fmt/actions/runs/18045326166/job/51354577497?pr=4551

@vitaut
Copy link
Copy Markdown
Contributor

vitaut commented Sep 26, 2025

I suggest opting out older gcc from this test, e.g. by checking FMT_GCC_VERSION.

@teruyamato0731
Copy link
Copy Markdown
Contributor Author

Thanks for the suggestion, @vitaut!

I tried using FMT_GCC_VERSION to conditionally compile the test, but it seems the root cause of the failure is different.

After taking a closer look at the CI logs, I noticed that the compilation error only occurs in the size-opt-test job, where FMT_BUILTIN_TYPES=0 is defined. In this configuration, it seems that const char* is being treated as a generic pointer rather than a C-style string. This triggers the static_assert that disallows formatting of non-void pointers.

Here is the key part of the error message:

In file included from /workspaces/fmt/include/fmt/format.h:41:0,
                 from /workspaces/fmt/include/fmt/os.h:11,
                 from /workspaces/fmt/src/os.cc:13:
/workspaces/fmt/include/fmt/base.h: In instantiation of ‘fmt::v12::detail::value<Context>::value(const T&) [with T = const char*; typename std::enable_if<(std::is_pointer<T>::value || std::is_member_pointer<T>::value), int>::type <anonymous> = 0; Context = fmt::v12::context]’:
/workspaces/fmt/include/fmt/base.h:2868:57:   required from ‘fmt::v12::remove_cvref_t<T> fmt::v12::format_to(OutputIt&&, fmt::v12::format_string<T ...>, T&& ...) [with OutputIt = fmt::v12::basic_appender<char>&; T = {fmt::v12::basic_string_view<char>&, const char (&)[3]}; typename std::enable_if<fmt::v12::detail::is_output_iterator<typename std::remove_cv<typename std::remove_reference<_From>::type>::type, char>::value, int>::type <anonymous> = 0; fmt::v12::remove_cvref_t<T> = fmt::v12::basic_appender<char>; fmt::v12::format_string<T ...> = fmt::v12::fstring<fmt::v12::basic_string_view<char>&, const char (&)[3]>]’
/workspaces/fmt/include/fmt/format-inl.h:96:56:   required from here
/workspaces/fmt/include/fmt/base.h:2261:5: error: static assertion failed: formatting of non-void pointers is disallowed
     static_assert(sizeof(T) == 0,
     ^
In file included from /workspaces/fmt/include/fmt/format.h:41:0,
                 from /workspaces/fmt/include/fmt/os.h:11,
                 from /workspaces/fmt/test/util.h:13,
                 from /workspaces/fmt/test/util.cc:8:
/workspaces/fmt/include/fmt/base.h: In instantiation of ‘fmt::v12::detail::value<Context>::value(const T&) [with T = const char*; typename std::enable_if<(std::is_pointer<T>::value || std::is_member_pointer<T>::value), int>::type <anonymous> = 0; Context = fmt::v12::context]’:
/workspaces/fmt/include/fmt/base.h:2868:57:   required from ‘fmt::v12::remove_cvref_t<T> fmt::v12::format_to(OutputIt&&, fmt::v12::format_string<T ...>, T&& ...) [with OutputIt = fmt::v12::basic_appender<char>&; T = {fmt::v12::basic_string_view<char>&, const char (&)[3]}; typename std::enable_if<fmt::v12::detail::is_output_iterator<typename std::remove_cv<typename std::remove_reference<_From>::type>::type, char>::value, int>::type <anonymous> = 0; fmt::v12::remove_cvref_t<T> = fmt::v12::basic_appender<char>; fmt::v12::format_string<T ...> = fmt::v12::fstring<fmt::v12::basic_string_view<char>&, const char (&)[3]>]’
/workspaces/fmt/include/fmt/format-inl.h:96:56:   required from here
/workspaces/fmt/include/fmt/base.h:2261:5: error: static assertion failed: formatting of non-void pointers is disallowed
     static_assert(sizeof(T) == 0,
     ^
cc1plus: error: unrecognized command line option "-Wno-dangling-else" [-Werror]
cc1plus: all warnings being treated as errors
cc1plus: error: unrecognized command line option "-Wno-dangling-else" [-Werror]
cc1plus: all warnings being treated as errors
gmake[2]: *** [test/CMakeFiles/size-opt-test.dir/build.make:118: test/CMakeFiles/size-opt-test.dir/util.cc.o] Error 1
gmake[2]: *** Waiting for unfinished jobs....
gmake[2]: *** [test/CMakeFiles/size-opt-test.dir/build.make:132: test/CMakeFiles/size-opt-test.dir/__/src/os.cc.o] Error 1
In file included from /workspaces/fmt/include/fmt/format.h:41:0,
                 from /workspaces/fmt/include/fmt/os.h:11,
                 from /workspaces/fmt/test/gtest-extra.h:15,
                 from /workspaces/fmt/test/gtest-extra.cc:8:
/workspaces/fmt/include/fmt/base.h: In instantiation of ‘fmt::v12::detail::value<Context>::value(const T&) [with T = const char*; typename std::enable_if<(std::is_pointer<T>::value || std::is_member_pointer<T>::value), int>::type <anonymous> = 0; Context = fmt::v12::context]’:
/workspaces/fmt/include/fmt/base.h:2868:57:   required from ‘fmt::v12::remove_cvref_t<T> fmt::v12::format_to(OutputIt&&, fmt::v12::format_string<T ...>, T&& ...) [with OutputIt = fmt::v12::basic_appender<char>&; T = {fmt::v12::basic_string_view<char>&, const char (&)[3]}; typename std::enable_if<fmt::v12::detail::is_output_iterator<typename std::remove_cv<typename std::remove_reference<_From>::type>::type, char>::value, int>::type <anonymous> = 0; fmt::v12::remove_cvref_t<T> = fmt::v12::basic_appender<char>; fmt::v12::format_string<T ...> = fmt::v12::fstring<fmt::v12::basic_string_view<char>&, const char (&)[3]>]’
/workspaces/fmt/include/fmt/format-inl.h:96:56:   required from here
/workspaces/fmt/include/fmt/base.h:2261:5: error: static assertion failed: formatting of non-void pointers is disallowed
     static_assert(sizeof(T) == 0,
     ^
cc1plus: error: unrecognized command line option "-Wno-dangling-else" [-Werror]
cc1plus: all warnings being treated as errors
gmake[2]: *** [test/CMakeFiles/size-opt-test.dir/build.make:104: test/CMakeFiles/size-opt-test.dir/gtest-extra.cc.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:876: test/CMakeFiles/size-opt-test.dir/all] Error 2
gmake: *** [Makefile:166: all] Error 2

The full log is quite long, but this seems to be the core issue.

I'm not familiar with the implications of FMT_BUILTIN_TYPES=0 and how it affects string handling. Do you have any advice on how to properly fix this for this specific build configuration?

@vitaut
Copy link
Copy Markdown
Contributor

vitaut commented Sep 28, 2025

It's not super clear to me from the error message where the string argument comes from and I wasn't able to repro the issue in https://www.godbolt.org/z/jqaEz1vP7. Do you have a godbolt example that demonstrates the error? Also I would recommend splitting test changes into a separate PR and just focus on docs in this one.

@teruyamato0731 teruyamato0731 marked this pull request as ready for review September 30, 2025 15:45
@vitaut vitaut merged commit 4801f54 into fmtlib:master Sep 30, 2025
40 checks passed
@vitaut
Copy link
Copy Markdown
Contributor

vitaut commented Sep 30, 2025

Merged, thank you!

@teruyamato0731
Copy link
Copy Markdown
Contributor Author

My pleasure.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Nov 2, 2025
# 12.1.0 - 2025-10-29

- Optimized `buffer::append`, resulting in up to ~16% improvement on spdlog
  benchmarks (fmtlib/fmt#4541). Thanks @fyrsta7.

- Worked around an ABI incompatibility in `std::locale_ref` between clang and
  gcc (fmtlib/fmt#4573).

- Made `std::variant` and `std::expected` formatters work with `format_as`
  (fmtlib/fmt#4574,
  fmtlib/fmt#4575). Thanks @phprus.

- Made `fmt::join<string_view>` work with C++ modules
  (fmtlib/fmt#4379,
  fmtlib/fmt#4577). Thanks @Arghnews.

- Exported `fmt::is_compiled_string` and `operator""_cf` from the module
  (fmtlib/fmt#4544). Thanks @CrackedMatter.

- Fixed a compatibility issue with C++ modules in clang
  (fmtlib/fmt#4548). Thanks @tsarn.

- Added support for cv-qualified types to the `std::optional` formatter
  (fmtlib/fmt#4561,
  fmtlib/fmt#4562). Thanks @OleksandrKvl.

- Added demangling support (used in exception and `std::type_info` formatters)
  for libc++ and clang-cl
  (fmtlib/fmt#4542,
  fmtlib/fmt#4560,
  fmtlib/fmt#4568,
  fmtlib/fmt#4571).
  Thanks @FatihBAKIR and @rohitsutreja.

- Switched to global `malloc`/`free` to enable allocator customization
  (fmtlib/fmt#4569,
  fmtlib/fmt#4570). Thanks @rohitsutreja.

- Made the `FMT_USE_CONSTEVAL` macro configurable by users
  (fmtlib/fmt#4546). Thanks @SnapperTT.

- Fixed compilation with locales disabled in the header-only mode
  (fmtlib/fmt#4550).

- Fixed compilation with clang 21 and `-std=c++20`
  (fmtlib/fmt#4552).

- Fixed a dynamic linking issue with clang-cl
  (fmtlib/fmt#4576,
  fmtlib/fmt#4584). Thanks @FatihBAKIR.

- Fixed a warning suppression leakage on gcc
  (fmtlib/fmt#4588). Thanks @ZedThree.

- Made more internal color APIs `constexpr`
  (fmtlib/fmt#4581). Thanks @ishani.

- Fixed compatibility with clang as a host compiler for NVCC
  (fmtlib/fmt#4564). Thanks @valgur.

- Fixed various warnings and lint issues
  (fmtlib/fmt#4565,
  fmtlib/fmt#4572,
  fmtlib/fmt#4557).
  Thanks @LiangHuDream and @teruyamato0731.

- Improved documentation
  (fmtlib/fmt#4549,
  fmtlib/fmt#4551,
  fmtlib/fmt#4566,
  fmtlib/fmt#4567,
  fmtlib/fmt#4578,).
  Thanks @teruyamato0731, @petersteneteg and @zimmerman-dev.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants