Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial specialization of formatter<string> after instantiation in gcc #3584

Closed
zptan opened this issue Aug 13, 2023 · 11 comments
Closed

Partial specialization of formatter<string> after instantiation in gcc #3584

zptan opened this issue Aug 13, 2023 · 11 comments

Comments

@zptan
Copy link

zptan commented Aug 13, 2023

Error

bazel-out/k8-opt/bin/external/fmt/libfmt/include/fmt/format.h:4076:1: error: partial specialization of 'struct fmt::v10::formatter<std::__cxx11::basic_string<_CharT>, Char>' after instantiation of 'struct fmt::v10::formatter<std::__cxx11::basic_string<char>, char, void>' [-fpermissive]
 4076 | FMT_FORMAT_AS(std::basic_string<Char>, basic_string_view<Char>);
      | ^~~~~~~~~~~~~
bazel-out/k8-opt/bin/external/fmt/libfmt/include/fmt/format.h:4078:1: error: partial specialization of 'struct fmt::v10::formatter<std::basic_string_view<Char>, Char>' after instantiation of 'struct fmt::v10::formatter<std::basic_string_view<char>, char, void>' [-fpermissive]
 4078 | FMT_FORMAT_AS(detail::std_string_view<Char>, basic_string_view<Char>);
      | ^~~~~~~~~~~~~

Env

OS: Ubuntu 22.04.3
Compiler: g++ 11.4.0

@vitaut
Copy link
Contributor

vitaut commented Aug 13, 2023

Please provide a godbolt repro.

@zptan
Copy link
Author

zptan commented Aug 13, 2023

Tried with godbolt, but unable to repro, don't know if some other lib(s) caused this

I solved the issue by

  • Replacing fmt::memory_buffer by std::string
  • Removing #include <fmt/format.h>

@zptan zptan closed this as completed Aug 13, 2023
@alex-700
Copy link

@vitaut

we faced the same problem too.

There is a minimal reproducer I was able to craft:
https://godbolt.org/z/dhjah7PMT

It compiles (e.g) in

  • clang + c++20 + fmt/10.1.0
  • clang + c++17 + fmt/10.1.0
  • gcc + c++20 + fmt/10.0.0
  • gcc + c++17 + fmt/10.1.0

Failes:

  • gcc + c++20 + fmt/10.1.0

@vitaut vitaut reopened this Aug 15, 2023
@vitaut vitaut removed the question label Aug 15, 2023
@vitaut
Copy link
Contributor

vitaut commented Aug 15, 2023

Thanks for the repro, reopened the issue.

@vitaut vitaut changed the title Failed to build app with fmt v10.1.0 Partial specialization of formatter<string> after instantiation in gcc Aug 15, 2023
@pauldreik
Copy link
Contributor

I git bisected this to commit 256a826

@vitaut
Copy link
Contributor

vitaut commented Aug 19, 2023

Fixed in bbb784f. Thanks for reporting.

@vitaut vitaut closed this as completed Aug 19, 2023
@windowsair
Copy link

Same issue. On older versions of fmtlib, moving #include <fmt/format.h> before #include <fmt/core.h> temporarily solves the problem.

@tocic
Copy link

tocic commented Apr 20, 2024

@vitaut
Experiencing a similar issue with this test project. Interestingly, it works in 10.0.0 and trunk, but doesn't work in 10.1.1 and 10.2.1. If this is expected (i.e. fixed on trunk), could you please provide a new release?

@vitaut
Copy link
Contributor

vitaut commented Apr 20, 2024

@tocic your example is incorrect: you should include fmt/format.h where formatter<string> is defined.

@tocic
Copy link

tocic commented Apr 20, 2024

@vitaut You mean in lib.h? I thought that I can use fmt/core.h in headers and fmt/format.h in sources to reduce the compilation time. Does the second example from the docs applies only to std::string_view? Maybe I should use const char* instead?

Note that formatter<string_view>::format is defined in fmt/format.h so it has to be included in the source file.

@vitaut
Copy link
Contributor

vitaut commented Apr 21, 2024

@tocic, the docs should be clearer about it but let's continue the discussion in #3942 since it's not directly related to the current issue.

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

No branches or pull requests

6 participants