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

"{}"_format(x) does not see to_string_view(x) anymore #1200

Closed
BillyDonahue opened this issue Jun 16, 2019 · 1 comment
Closed

"{}"_format(x) does not see to_string_view(x) anymore #1200

BillyDonahue opened this issue Jun 16, 2019 · 1 comment

Comments

@BillyDonahue
Copy link
Contributor

I'd expect this to work, and it does in libfmt 5.3.0.
https://gcc.godbolt.org/z/kVkM09 (clang-8.0, libfmt-5.3.0)

It is broken in trunk libfmt:
https://gcc.godbolt.org/z/mNHi1D (clang-8.0, libfmt-trunk)

#include <string>
#include <fmt/format.h>

namespace u {
struct X {};
fmt::string_view to_string_view(const X&) { return "abc"; }
}  // namespace u

std::string func(const u::X& x) {
    return fmt::format("X:{}", x);
}

std::string lit(const u::X& x) {
    using namespace fmt::literals;
    return "X:{}"_format(x);
}

Only the _format literal is broken. The fmt::format call is ok in both cases.

In file included from <source>:2:
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/format.h:2115:7: error: call to deleted constructor of 'conditional_t<has_formatter<X, buffer_context<char_type> >::value, formatter<u::X, char_type>, internal::fallback_formatter<X, char_type> >' (aka 'fmt::v5::internal::fallback_formatter<u::X, char, void>')
      f;
      ^
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/format.h:2126:23: note: in instantiation of function template specialization 'fmt::v5::internal::parse_format_specs<u::X, fmt::v5::basic_parse_context<char, fmt::v5::internal::error_handler> >' requested here
        parse_funcs_{&parse_format_specs<Args, parse_context_type>...} {}
                      ^
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/format.h:2173:54: note: in instantiation of member function 'fmt::v5::internal::format_string_checker<char, fmt::v5::internal::error_handler, u::X>::format_string_checker' requested here
  format_string_checker<Char, ErrorHandler, Args...> checker(s, eh);
                                                     ^
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/format.h:3539:9: note: in instantiation of function template specialization 'fmt::v5::internal::do_check_format_string<char, fmt::v5::internal::error_handler, u::X>' requested here
        do_check_format_string<Char, error_handler, Args...>(
        ^
<source>:15:25: note: in instantiation of function template specialization 'fmt::v5::internal::udl_formatter<char, 'X', ':', '{', '}'>::operator()<u::X>' requested here
    return "X:{}"_format(x);
                        ^
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/core.h:602:3: note: 'fallback_formatter' has been explicitly marked deleted here
  fallback_formatter() = delete;
  ^
1 error generated.
Compiler returned: 1
@vitaut
Copy link
Contributor

vitaut commented Jun 16, 2019

Fixed in 4912cff. Thanks for reporting!

@vitaut vitaut closed this as completed Jun 16, 2019
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