Skip to content

FMT_STRING text align fails with custom operator<< #1692

@Naios

Description

@Naios

bd88040

It seems like this issue was introduced between 3860edc and bd88040.

Valid on:

  • Clang 10
  • GCC 10.1
  • MSVC 16.5.4

Minimal reproducible example:

https://gcc.godbolt.org/z/5CYkGG

#include <fmt/chrono.h>
#include <fmt/compile.h>
#include <fmt/core.h>
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <fmt/compile.h>
#include <fmt/color.h>
#include <ostream>

struct custom_print {
  friend std::ostream& operator << (std::ostream& os, custom_print const&) {
      return os << "huhu";
  }
};

int main() {
    fmt::format(FMT_STRING("{:<7}"), custom_print{});
    return 0;
}

Error message:

In file included from <source>:2:

In file included from /opt/compiler-explorer/libs/fmt/6.2.1/include/fmt/chrono.h:16:

/opt/compiler-explorer/libs/fmt/6.2.1/include/fmt/format.h:2703:27: error: constexpr variable 'invalid_format' must be initialized by a constant expression

  FMT_CONSTEXPR_DECL bool invalid_format = internal::do_check_format_string<

                          ^                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/opt/compiler-explorer/libs/fmt/6.2.1/include/fmt/core.h:1655:3: note: in instantiation of function template specialization 'fmt::v6::internal::check_format_string<custom_print, FMT_COMPILE_STRING, 0>' requested here

  check_format_string<Args...>(format_str);

  ^

/opt/compiler-explorer/libs/fmt/6.2.1/include/fmt/core.h:1747:17: note: in instantiation of function template specialization 'fmt::v6::internal::make_args_checked<custom_print, FMT_COMPILE_STRING, char>' requested here

      internal::make_args_checked<Args...>(format_str, args...));

                ^

<source>:18:10: note: in instantiation of function template specialization 'fmt::v6::format<FMT_COMPILE_STRING, custom_print, char>' requested here

    fmt::format(FMT_STRING("{:<7}"), custom_print{});

         ^

/opt/compiler-explorer/libs/fmt/6.2.1/include/fmt/format.h:2638:12: note: non-constexpr function 'parse' cannot be used in a constant expression

  return f.parse(ctx);

           ^

/opt/compiler-explorer/libs/fmt/6.2.1/include/fmt/format.h:2669:33: note: in call to 'parse_format_specs(checker.context_)'

    return arg_id_ < num_args ? parse_funcs_[arg_id_](context_) : begin;

                                ^

/opt/compiler-explorer/libs/fmt/6.2.1/include/fmt/format.h:2615:21: note: in call to '&checker->on_format_specs(&"{:<7}"[2], &"{:<7}"[5])'

        p = handler.on_format_specs(p + 1, end);

                    ^

/opt/compiler-explorer/libs/fmt/6.2.1/include/fmt/format.h:2696:3: note: in call to 'parse_format_string({&"{:<7}"[0], 5}, checker)'

  parse_format_string<true>(s, checker);

  ^

/opt/compiler-explorer/libs/fmt/6.2.1/include/fmt/format.h:2703:44: note: in call to 'do_check_format_string({&"{:<7}"[0], 5}, {})'

  FMT_CONSTEXPR_DECL bool invalid_format = internal::do_check_format_string<

                                           ^

/opt/compiler-explorer/libs/fmt/6.2.1/include/fmt/ostream.h:113:8: note: declared here

  auto parse(basic_format_parse_context<Char>& ctx) -> decltype(ctx.begin()) {

       ^

1 error generated.

Compiler returned: 1

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