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

nested_formatter compilation errors #3809

Closed
sergiud opened this issue Jan 15, 2024 · 1 comment
Closed

nested_formatter compilation errors #3809

sergiud opened this issue Jan 15, 2024 · 1 comment

Comments

@sergiud
Copy link
Contributor

sergiud commented Jan 15, 2024

Using GCC 6.4.0 the API reference example

#include <fmt/format.h>

struct point {
  double x, y;
};

template <>
struct fmt::formatter<point> : nested_formatter<double> {
  auto format(point p, format_context& ctx) const {
    return write_padded(ctx, [=](auto out) {
      return format_to(out, "({}, {})", nested(p.x), nested(p.y));
    });
  }
};

int main() {
  fmt::print("[{:>20.2f}]", point{1, 2});
}

and the corresponding unit test produce compilation errors such as

error: cannot call member function 'fmt::v10::nested_view<T> fmt::v10::nested_formatter<T>::nested(const T&) const [with T = double]' without object
       return format_to(out, "({}, {})", nested(p.x), nested(p.y));

Reproducer: https://godbolt.org/z/6WoeMcs6a

@phprus
Copy link
Contributor

phprus commented Jan 15, 2024

Fix: #3810

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

3 participants