You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Constant evaluation rejects "new wchar_t[n]{L\"...\"}" although n is large enough #501
During constant evaluation, the check that the initializer of an array
new-expression fits in the allocated array uses the size in bytes of a string
literal initializer instead of its number of characters. So when the elements
are wider than one byte, an array that is large enough is reported as too
small:
constexprintf(int n) {
auto p = newwchar_t[n]{L"ab"};
int r = p[1];
delete[] p;
return r;
}
static_assert(f(3) == L'b');
error: expression must have a constant value
note: number of dynamically-allocated elements (3) too small for initializer
The same happens with char16_t and char32_t arrays; char and char8_t
arrays are not affected. (Found by CodeRabbit while reviewing #495.)
Activity
Count the characters, not the bytes, of a string literal initializer …