Skip to content

Compile-time checking does not work with named argument of a custom type #2816

Description

@timsong-cpp

https://godbolt.org/z/haoG1o3Pq

#include <fmt/format.h>

struct E {};
template<>
struct fmt::formatter<E> : fmt::formatter<std::string_view> {
    auto format(E, auto& ctx) const { return fmt::formatter<std::string_view>::format("42", ctx); }
};

void f() {
    using namespace fmt::literals;
    (void) fmt::format("{a}", "a"_a = E());
}

with -std=c++2a/2b:

In file included from /opt/compiler-explorer/libs/fmt/trunk/include/fmt/format.h:49,
                 from <source>:1:
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/core.h: In instantiation of 'constexpr decltype (ctx.begin()) fmt::v8::detail::parse_format_specs(ParseContext&) [with T = statically_named_arg<E, char, 2, fmt::v8::detail_exported::fixed_string<char, 2>{"a"}>; ParseContext = compile_parse_context<char, error_handler>; decltype (ctx.begin()) = const char*]':
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/core.h:2894:22:   required from 'constexpr fmt::v8::detail::format_string_checker<Char, ErrorHandler, Args>::format_string_checker(fmt::v8::basic_string_view<Char>, ErrorHandler) [with Char = char; ErrorHandler = fmt::v8::detail::error_handler; Args = {fmt::v8::detail::statically_named_arg<E, char, 2, fmt::v8::detail_exported::fixed_string<char, 2>{"a"}>}]'
<source>:11:23:   required from here
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/core.h:2658:12: error: use of deleted function 'fmt::v8::detail::fallback_formatter<T, Char, Enable>::fallback_formatter() [with T = fmt::v8::detail::statically_named_arg<E, char, 2, fmt::v8::detail_exported::fixed_string<char, 2>{"a"}>; Char = char; Enable = void]'
 2658 |   auto f = conditional_t<has_formatter<mapped_type, context>::value,
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2659 |                          formatter<mapped_type, char_type>,
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2660 |                          fallback_formatter<T, char_type>>();
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/core.h:1013:3: note: declared here
 1013 |   fallback_formatter() = delete;
      |   ^~~~~~~~~~~~~~~~~~
Compiler returned: 1

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions