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

arg_id with fmt::arg() and width specifier stopped compiling (since fmt 11.1.0) #4348

Closed
jolz opened this issue Feb 13, 2025 · 4 comments
Closed

Comments

@jolz
Copy link

jolz commented Feb 13, 2025

here's my sample code (based on https://fmt.dev/dev/syntax/ "Box drawing using Unicode fill")

#include <fmt/core.h>

int main() {
    fmt::print(
        "┌{0:─^{width}}┐\n"
        "│{label: ^{width}}│\n"
        "└{0:─^{width}}┘\n",
        "", fmt::arg("label", "Hello, world!"), fmt::arg("width", 20));

}

compile error message with fmt-trunk and -std=c++20:

<source>:4:15:   in 'constexpr' expansion of 'fmt::v11::fstring<const char (&)[1], int, fmt::v11::detail::named_arg<char, char [14]>, fmt::v11::detail::named_arg<char, int> >("\37777777742\37777777624\37777777614{0:\37777777742\37777777624\37777777600^{1}}\37777777742\37777777624\37777777620\012\37777777742\37777777624\37777777602{label: ^{1}}\37777777742\37777777624\37777777602\012\37777777742\37777777624\37777777624{0:\37777777742\37777777624\37777777600^{1}}\37777777742\37777777624\37777777630\012")'
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/base.h:2708:53:   in 'constexpr' expansion of 'fmt::v11::detail::parse_format_string<char, format_string_checker<char, 4, 0, true> >(fmt::v11::basic_string_view<char>(((const char*)s)), fmt::v11::detail::format_string_checker<char, 4, 0, true>(fmt::v11::basic_string_view<char>(((const char*)s)), (fmt::v11::fstring<const char (&)[1], int, fmt::v11::detail::named_arg<char, char [14]>, fmt::v11::detail::named_arg<char, int> >::arg_pack(), fmt::v11::fstring<const char (&)[1], int, fmt::v11::detail::named_arg<char, char [14]>, fmt::v11::detail::named_arg<char, int> >::arg_pack())))'
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/base.h:1624:32: error: 'constexpr void fmt::v11::detail::format_string_checker<Char, NUM_ARGS, NUM_NAMED_ARGS, DYNAMIC_NAMES>::on_error(const char*) [with Char = char; int NUM_ARGS = 4; int NUM_NAMED_ARGS = 0; bool DYNAMIC_NAMES = true]' called in a constant expression
 1624 |         return handler.on_error("unmatched '}' in format string");
      |                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • test in godbolt (gcc-14.2, -std=c++20, fmt-trunk) : https://godbolt.org/z/KPTPzcjjb
  • switch to "fmt-11.0.0" to see it working
  • switch to "-std=c++17" to see it working (no consteval)
  • last "good" fmt-version : 11.0.2
  • first "failed" fmt-version: 11.1.0
@jolz jolz changed the title arg_id with fmt::arg() ans width specifier stopped compiling (since fmt 11.1.0) arg_id with fmt::arg() and width specifier stopped compiling (since fmt 11.1.0) Feb 13, 2025
@vitaut
Copy link
Contributor

vitaut commented Feb 13, 2025

Same as #3817.

@dinomight
Copy link
Contributor

@vitaut Are you sure this is a duplicate of #3817 ? I'm seeing this same compilation error in this sample. It seems related to dynamic formatting with named arguments. Surprisingly, switching to a runtime format string works.

fmt::format("{a:<{size}}", fmt::arg("a", 1), fmt::arg("size", 10));  // Fails to compile.
fmt::format("{a:{size}}", fmt::arg("a", 1), fmt::arg("size", 10));  // Fails to compile.
fmt::format("{a:<10}", fmt::arg("a", 1), fmt::arg("size", 10));  // Compiles and formats correctly.
fmt::format("{:<{}}", 1, 10);  // Compiles and formats correctly.
fmt::format("{0:<{1}}", 1, 10);  // Compiles and formats correctly.
fmt::format(fmt::runtime("{a:<{size}}"), fmt::arg("a", 1), fmt::arg("size", 10));  // Compiles and formats correctly.

Things work in 11.0.2, but compile fails in 11.1.3 in VS 17.14 Preview 1.

@vitaut
Copy link
Contributor

vitaut commented Feb 22, 2025

It is a duplicate and your example is only superficially similar, please open a separate issue.

@dinomight
Copy link
Contributor

Created new issue #4360

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

No branches or pull requests

3 participants