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

format-family methods should accept args as const references #2487

Closed
0x804d8000 opened this issue Sep 6, 2021 · 3 comments
Closed

format-family methods should accept args as const references #2487

0x804d8000 opened this issue Sep 6, 2021 · 3 comments

Comments

@0x804d8000
Copy link

#2462 fixed an inconsistency between signatures of format-family methods, in a way that now all of them accept args as universal references.

Unfortunately, universal references are not quite "universal" in that they can't be bound to bit fields, e.g.:

struct C {
  int f : 1;
};

C c = {.f = 1};

void foo() {
  char buf[10];
  format_to_n(buf, 10, "{}", c.f);  // Compiles before #2462, no longer compiles now.
}

This might be a long-standing issue with format and format_to, I suppose.

To fix this, I suggest that we should instead accept args as const references for all of format-family methods.

@ethanvc
Copy link

ethanvc commented Sep 6, 2021

人家才统一改成 universal referenece,你就来拆台了。

@foonathan
Copy link
Contributor

foonathan commented Sep 6, 2021

The choice to use forwarding references here is intentional to support formatting of ranges, see: https://wg21.link/p2418

@0x804d8000
Copy link
Author

Thanks for mentioning P2418, I wasn't aware of it.

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