Bug 13907 – Surrogate pairs in wchar string literal will cause incorrect length match
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-12-29T01:54:00Z
Last change time
2015-02-18T03:41:35Z
Keywords
accepts-invalid, pull, rejects-valid
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2014-12-29T01:54:38Z
Example code:
void f1(wchar[1] a) {}
void f2(wchar[2] a) {}
void f3(wchar[3] a) {}
auto f12(wchar[1]) { return 1; }
auto f12(wchar[2]) { return 2; }
void main()
{
// Surrogate pair is used for U+10000
wstring s = "\U00010000"w;
assert(s.length == 2);
// ok
f2("\U00010000"w);
f2("\U00010000");
// Why the wstring length == 2 matches to wchar[1]?
f1("\U00010000"w);
f1("\U00010000" );
// Why the wstring length == 2 matches to wchar[3]?
f3("\U00010000"w);
f3("\U00010000" );
// This is ok, but...
assert(f12("ab"w) == 2);
// I think the wchar[2] version should be selected, but doesn't.
assert(f12("\U00010000"w) == 2);
}