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.syn] A wrong exposition for std::format definition #4877

Closed
xmh0511 opened this issue Sep 8, 2021 · 2 comments
Closed

[format.syn] A wrong exposition for std::format definition #4877

xmh0511 opened this issue Sep 8, 2021 · 2 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Sep 8, 2021

The definition for std::format is as the following

template<class... Args>
string format(format-string<Args...> fmt, const Args&... args);

template<class... Args>
wstring format(wformat-string<Args...> fmt, const Args&... args);
// .....

In this definition, the format-string or wformat-string is an alias template, defined as the following

template<class... Args>
using format-string =   basic-format-string<char, type_identity_t<Args>...>;                      // exposition only
      
template<class... Args>
using wformat-string =  basic-format-string<wchar_t, type_identity_t<Args>...>;                            // exposition only
     

where basic-format-string is a class template, It arguably says the first parameters of std::formart in this two cases are class template specialization. We also gives a simple use of std::format in the subsequent clauses, which is

string s0 = format("{} to {}",   "a", "b"); // OK, automatic indexing

The first argument has an array type, in template function call deduction, it is decayed to a pointer to participate the deduction, which means basic-format-string<char, type_identity_t<Args>...> will compare with pointer to const char, as per [temp.deduct.type#2], the deduction on this pair cannot be done. The deduction will fail.

@CaseyCarter
Copy link
Contributor

There is nothing to deduce in basic-format-string<char, type_identity_t<Args>...> (ditto for the wchar_t case): the Args are wrapped in type_identity_t specifically so they will be non-deducible. FTAD then only deduces Args from the other arguments - as intended - which is enough to fully specify the specialization of basic-format-string used for either format overload.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 8, 2021

Ah, type_identity_t is a non-deduced context.

@xmh0511 xmh0511 closed this as completed Sep 8, 2021
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

2 participants