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

On GCC C++20, formatting std::string using core.h, then including format.h, causes partial specialization error #2769

Closed
nyanpasu64 opened this issue Feb 16, 2022 · 4 comments

Comments

@nyanpasu64
Copy link

After upgrading from fmtlib 7.1.3 to 8.1.1, I started getting a mysterious compilation error on Arch Linux GCC 11.2.0 C++20 (but no error on Clang 13.0.1):

In file included from /home/nyanpasu64/code/exotracker-cpp/src/serialize.cpp:4:
/home/nyanpasu64/code/exotracker-cpp/3rdparty/fmt_/include/fmt/format.h:2582:10: error: partial specialization of ‘struct fmt::v8::formatter<std::__cxx11::basic_string<_CharT>, Char>’ after instantiation of ‘struct fmt::v8::formatter<std::__cxx11::basic_string<char>, char, void>’ [-fpermissive]
 2582 |   struct formatter<Type, Char> : formatter<Base, Char> {                 \
      |          ^~~~~~~~~~~~~~~~~~~~~
/home/nyanpasu64/code/exotracker-cpp/3rdparty/fmt_/include/fmt/format.h:2597:1: note: in expansion of macro ‘FMT_FORMAT_AS’
 2597 | FMT_FORMAT_AS(std::basic_string<Char>, basic_string_view<Char>);
      | ^~~~~~~~~~~~~

Annoyingly, this error doesn't point to where the concrete formatter was instantiated.

A minimal test case for this behavior is as follows:

#include <string>
#include <fmt/core.h>
inline void f() {
    (void) fmt::format("{}", std::string());
}
#include <fmt/format.h>
int main() {}

The error can be reproduced using g++ -std=gnu++20 fmt-err.cpp and c++20, but not gnu++17 and below, and not using clang++ with gnu++20 or gnu++17.

Is this intended to function properly? (I should probably stop using fmtlib in my headers... it's rather sloppy on my part.)

@vitaut
Copy link
Contributor

vitaut commented Feb 16, 2022

Repro: https://godbolt.org/z/35WPeoM6P

nyanpasu64 added a commit to nyanpasu64/exotracker-cpp that referenced this issue Feb 16, 2022
@vitaut
Copy link
Contributor

vitaut commented Feb 16, 2022

Fixed in a1ea3e0, thanks for reporting.

@vitaut vitaut closed this as completed Feb 16, 2022
@nyanpasu64
Copy link
Author

Out of curiosity, why does the error only occur on GCC C++20 mode?

@vitaut
Copy link
Contributor

vitaut commented Feb 16, 2022

I'm not sure why it only happens in C++20.

facebook-github-bot pushed a commit to facebook/fbthrift that referenced this issue Jun 10, 2022
Summary: Workaround a compilation issue on C++20 by switching from `fmt::string_view` to `boost::string_view`. A proper fix (fmtlib/fmt#2769) will be backported separately.

Differential Revision: D37076763

fbshipit-source-id: d8001bdcd65ee9edf1f265e3aaf281c196e4d155
facebook-github-bot pushed a commit to facebookarchive/profilo that referenced this issue Jun 10, 2022
Summary: Backport a fix to fmtlib/fmt#2769.

Reviewed By: aandreyeu

Differential Revision: D37077479

fbshipit-source-id: 6f9d716c47784717c4aa36eba89498639eb3503a
EduardoCostaom added a commit to EduardoCostaom/profilo that referenced this issue Nov 2, 2022
Summary: Backport a fix to fmtlib/fmt#2769.

Reviewed By: aandreyeu

Differential Revision: D37077479

fbshipit-source-id: 6f9d716c47784717c4aa36eba89498639eb3503a
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

2 participants