Skip to content

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

Closed
@nyanpasu64

Description

@nyanpasu64

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions