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

g++-10 compilation error when including fmt/ostream.h #2479

Closed
MichaelTrikergiotis opened this issue Sep 1, 2021 · 5 comments
Closed

g++-10 compilation error when including fmt/ostream.h #2479

MichaelTrikergiotis opened this issue Sep 1, 2021 · 5 comments

Comments

@MichaelTrikergiotis
Copy link

MichaelTrikergiotis commented Sep 1, 2021

Including the fmt/ostream.h header when using g++-10 with -std=c++20, stops compilation with an error.

The issue doesn't exist with clang 12 or the latest MSVC.

compiler : g++ 10.3.0 with -std=c++20
OS : Ubuntu 21.04
fmt : 8.0.1

The issue also exists in fmt 8.0.
This issue doesn't exist in fmt 7.1.3.

Working example :

#define FMT_HEADER_ONLY 
#include "fmt/core.h"

int main()
{
	fmt::print("Works.\n");
}

The above compiled with g++-10 -std=c++20 with no problems.

Not working example, with link to godbolt : https://gcc.godbolt.org/z/7n6hPsdj8 :

#define FMT_HEADER_ONLY 
#include "fmt/core.h"
#include "fmt/ostream.h"

int main()
{
	fmt::print("Doesn't work.\n");
}

Trying to compile with g++-10 -std=c++20 :

In file included from bad.cpp:3:
fmt/ostream.h:123:8: error: partial specialization of ‘struct fmt::v8::detail::fallback_formatter<T, Char, typename std::enable_if<fmt::v8::detail::is_streamable<T, Char>::value, void>::type>’ after instantiation of ‘struct fmt::v8::detail::fallback_formatter<char [7], char, void>’ [-fpermissive]
  123 | struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fmt/ostream.h:123:8: error: partial specialization of ‘struct fmt::v8::detail::fallback_formatter<T, Char, typename std::enable_if<fmt::v8::detail::is_streamable<T, Char>::value, void>::type>’ after instantiation of ‘struct fmt::v8::detail::fallback_formatter<char [3], char, void>’ [-fpermissive]
fmt/ostream.h:123:8: error: partial specialization of ‘struct fmt::v8::detail::fallback_formatter<T, Char, typename std::enable_if<fmt::v8::detail::is_streamable<T, Char>::value, void>::type>’ after instantiation of ‘struct fmt::v8::detail::fallback_formatter<char [1], char, void>’ [-fpermissive]
@OnurKader
Copy link

Removing the header only macro seems to fix the issue (I hope header only is not mandatory).

godbolt

@MichaelTrikergiotis
Copy link
Author

I need fmt in header only mode so removing the #define FMT_HEADER_ONLY macro is not possible for me.
The code in the post is just the smallest possible repro, and so I have included the macro on purpose.

@sunmy2019
Copy link
Contributor

sunmy2019 commented Sep 1, 2021

It is a design defect. To solve this, we need to reorganize the code.

#include "fmt/core.h"
#include "fmt/ostream.h"

// this file should be the last, but it is now included in the `core.h`
#include "fmt/format-inl.h"

@sunmy2019
Copy link
Contributor

A temporary fix would be https://gcc.godbolt.org/z/xn3YenGxe

#include <fmt/core.h>
#include <fmt/ostream.h>
#define FMT_HEADER_ONLY
#undef FMT_FUNC
#define FMT_FUNC inline
#include <fmt/format-inl.h>

int main() {
  fmt::print("Doesn't work.\n");
}

@vitaut
Copy link
Contributor

vitaut commented Sep 3, 2021

Fixed in 20931ba. Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants