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

Fix handling of types with custom formatters that are convertible to std::string_view #1451

Merged

Conversation

denizevrenci
Copy link
Contributor

@denizevrenci denizevrenci commented Dec 4, 2019

I agree that my contributions are licensed under the {fmt} license, and agree to future changes to the licensing.

I commented at the PR (#1342) as well but types that are convertible to std::string_view have ambiguous lookup after that change.

I am not sure if this is the right solution but I wanted to start the discussion here. And this change fixes the ambiguous lookup in my case.

@vitaut
Copy link
Contributor

vitaut commented Dec 4, 2019

Thanks! Could you add a test case similar to

fmt/test/core-test.cc

Lines 620 to 627 in 123e7f7

struct explicitly_convertible_to_std_string_view {
explicit operator std::string_view() const { return "foo"; }
};
TEST(FormatterTest, FormatExplicitlyConvertibleToStdStringView) {
EXPECT_EQ("foo",
fmt::format("{}", explicitly_convertible_to_std_string_view()));
}
?

@denizevrenci denizevrenci force-pushed the fix_types_convertible_to_string_view branch from d88bc82 to 851c20f Compare December 5, 2019 04:13
@denizevrenci
Copy link
Contributor Author

denizevrenci commented Dec 5, 2019

I dug a little deeper into this issue and understood that the conflict is caused by the existence of a custom formatter. My earlier fix disables the custom formatter and uses the default std::string_view formatter. So the test that I just added does not pass with or without the fix.

Here is the error: https://travis-ci.org/fmtlib/fmt/jobs/620950783#L716

@denizevrenci denizevrenci changed the title Fix handling of types that are explicitly convertible to std::string_view Fix handling of types with custom formatters that are convertible to std::string_view Dec 5, 2019
@denizevrenci denizevrenci force-pushed the fix_types_convertible_to_string_view branch from 851c20f to bbcb02c Compare December 5, 2019 04:28
@denizevrenci
Copy link
Contributor Author

I pushed a new fix that I think addresses this issue.

test/custom-formatter-test.cc Outdated Show resolved Hide resolved
test/custom-formatter-test.cc Outdated Show resolved Hide resolved
test/custom-formatter-test.cc Outdated Show resolved Hide resolved
test/custom-formatter-test.cc Outdated Show resolved Hide resolved
test/custom-formatter-test.cc Outdated Show resolved Hide resolved
@denizevrenci denizevrenci force-pushed the fix_types_convertible_to_string_view branch from bbcb02c to 206c186 Compare December 6, 2019 01:16
@vitaut vitaut merged commit 1ab80aa into fmtlib:master Dec 6, 2019
@vitaut
Copy link
Contributor

vitaut commented Dec 6, 2019

LGTM, thanks!

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

Successfully merging this pull request may close these issues.

2 participants