Created on 2020-03-17.00:00:00 last changed 16 months ago
Proposed resolution (approved by CWG 2023-02-07):
Change in 12.2.2.9 [over.match.class.deduct] paragraph 1.8 as follows:
- if ei is of array type and xi is a braced-init-list
or string-literal, Ti is an rvalue reference to the declared type of ei, and- if ei is of array type and xi is a string-literal, Ti is an lvalue reference to the const-qualified declared type of ei, and
- ...
Append to the example in 12.2.2.9 [over.match.class.deduct] paragraph 2 as follows:
G g(true, 'a', 1); // OK, deduces G<char, bool>
template<class T, std::size_t N> struct H { T array[N]; }; template<class T, std::size_t N> struct I { volatile T array[N]; }; template<std::size_t N> struct J { unsigned char array[N]; }; H h = { "abc" }; // OK, deduces H<char, 4> (not T = const char) I i = { "def" }; // OK, deduces I<char, 4> J j = { "ghi" }; // error: cannot bind reference to array of unsigned char to array of char in deduction
[Accepted as a DR at the February, 2023 meeting.]
Consider:
template<typename T, std::size_t N> struct A { T array[N]; }; A a = { "meow" };
The current wording says in 12.2.2.9 [over.match.class.deduct] bullet 1.8:
- if ei is of array type and xi is a braced-init-list or string-literal, Ti is an rvalue reference to the declared type of ei, and
- ...
This will fail overload resolution, because a string literal (which is an lvalue) does not match a parameter of type T (&&)[N].
History | |||
---|---|---|---|
Date | User | Action | Args |
2023-07-16 13:00:43 | admin | set | status: open -> c++23 |
2023-07-16 13:00:43 | admin | set | status: dr -> open |
2023-02-18 18:43:04 | admin | set | status: ready -> dr |
2023-02-10 23:01:52 | admin | set | status: tentatively ready -> ready |
2023-02-07 17:41:05 | admin | set | status: review -> tentatively ready |
2023-01-28 21:44:57 | admin | set | status: open -> review |
2023-01-14 22:16:14 | admin | set | messages: + msg7132 |
2020-03-17 00:00:00 | admin | create |