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

Improve error message when formatting unknown types #872

Merged
merged 1 commit into from
Sep 20, 2018

Conversation

foonathan
Copy link
Contributor

This replaces the confusing "use of incomplete type" when formatting an unknown type with a nice static_assert, like this:

In file included from /home/foonathan/Programming/fmt/include/fmt/format.h:54,
                 from /home/foonathan/Programming/fmt/test/add-subdirectory-test/main.cc:1:
/home/foonathan/Programming/fmt/include/fmt/core.h: In instantiation of ‘struct fmt::v5::formatter<ostream_only, char, void>’:
/home/foonathan/Programming/fmt/include/fmt/core.h:590:56:   required from ‘static void fmt::v5::internal::value<Context>::format_custom_arg(const void*, Context&) [with T = ostream_only; Context = fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char>]’
/home/foonathan/Programming/fmt/include/fmt/core.h:576:19:   required from ‘fmt::v5::internal::value<Context>::value(const T&) [with T = ostream_only; Context = fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char>]’
/home/foonathan/Programming/fmt/include/fmt/core.h:604:58:   required from ‘constexpr fmt::v5::internal::init<Context, T, TYPE>::operator fmt::v5::internal::value<Context>() const [with Context = fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char>; T = const ostream_only&; fmt::v5::internal::type TYPE = (fmt::v5::internal::type)13]’
/home/foonathan/Programming/fmt/include/fmt/core.h:1008:35:   required from ‘typename std::enable_if<IS_PACKED, fmt::v5::internal::value<Context> >::type fmt::v5::internal::make_arg(const T&) [with bool IS_PACKED = true; Context = fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char>; T = ostream_only; typename std::enable_if<IS_PACKED, fmt::v5::internal::value<Context> >::type = fmt::v5::internal::value<fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char> >]’
/home/foonathan/Programming/fmt/include/fmt/core.h:1066:51:   required from ‘fmt::v5::format_arg_store<Context, Args>::format_arg_store(const Args& ...) [with Context = fmt::v5::basic_format_context<std::back_insert_iterator<fmt::v5::internal::basic_buffer<char> >, char>; Args = {ostream_only}]’
/home/foonathan/Programming/fmt/include/fmt/core.h:1444:45:   required from ‘void fmt::v5::print(fmt::v5::string_view, const Args& ...) [with Args = {ostream_only}; fmt::v5::string_view = fmt::v5::basic_string_view<char>]’
/home/foonathan/Programming/fmt/test/add-subdirectory-test/main.cc:9:36:   required from here
/home/foonathan/Programming/fmt/include/fmt/core.h:350:19: error: static assertion failed: don't know how to format the type, include fmt/ostream.h if the type provides an operator<< that should be used
     static_assert(no_formatter_error<T>::value,
                   ^~~~~~~~~~~~~~~~~~~~~

(well, "nice", you've still got the whole error message stack)

This should hopefully reduce the number of issues like #871.

@foonathan
Copy link
Contributor Author

I don't think the build error is my fault...

@vitaut vitaut merged commit 9d2221b into master Sep 20, 2018
@vitaut
Copy link
Contributor

vitaut commented Sep 20, 2018

Thanks!

@vitaut vitaut deleted the error-message-improvement branch September 20, 2018 19:02
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