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

Bug: fmt::print(...) infinite recursion when using std::filesystem::path and fmt/ranges.h header is included #1268

Closed
odygrd opened this issue Aug 18, 2019 · 5 comments

Comments

@odygrd
Copy link

odygrd commented Aug 18, 2019

Executing the following code will enter an infinite recursion and the program will crash

template <typename... Args>
auto capture(const Args&... args) {
return std::make_tuple(args...);
}

auto print_message = [](const auto&... args) {
fmt::print(args...);
};

int main()
{
std::filesystem::path ph {"test_path"};

auto args = capture("{}", ph);

std::apply(print_message, args);
}

@vitaut
Copy link
Contributor

vitaut commented Aug 19, 2019

I wasn't able to make your example compile: https://godbolt.org/z/FKJcEH. Please provide more details including the compiler version and {fmt} library version.

@odygrd
Copy link
Author

odygrd commented Aug 19, 2019

I see it doesn't compile.
I am using gcc 9.1 and the libfmt version was very recent from master last updated about ~15/20 days ago but I don't have the exact commit hash.
Maybe you've changed something within that period

@odygrd
Copy link
Author

odygrd commented Aug 19, 2019

I made it compile on godbolt

https://godbolt.org/z/g1c6Q-

When fmt/ranges.h is not included the program runs fine.

If I #include fmt/ranges.h it will crash

I get ~94000 lines of stack so it is hard to copy paste here but it looks like this

image001

@odygrd odygrd changed the title Bug: fmt::print(...) infinite recursion when using std::filesystem::path Bug: fmt::print(...) infinite recursion when using std::filesystem::path and fmt/ranges.h header is included Aug 19, 2019
@vitaut
Copy link
Contributor

vitaut commented Aug 21, 2019

The problem is that std::filesystem::path looks like a range because it has begin() and end() which enables formatter specialization for ranges. However the latter should really be disabled because path is an infinitely deep range of itself 🤦‍♂️ (corrected: it has nothing to do with conversion to std::string, just poor design of the path API).

@vitaut
Copy link
Contributor

vitaut commented Aug 21, 2019

Fixed in b2d4ca1. Thanks for reporting!

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