D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14627 - Implicit conversion from uint to dchar allows dchar > dchar.max
Summary: Implicit conversion from uint to dchar allows dchar > dchar.max
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-28 16:58 UTC by Lionello Lunesu
Modified: 2024-12-13 18:43 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Lionello Lunesu 2015-05-28 16:58:03 UTC
This code compiles & runs:

void main()
{
  uint u = ~0;
  dchar d = u;//implicit conversion
  assert(d > d.max);
}

It should use VRP to determine whether the range fits dchar range.
~
~
~
~
~
Comment 1 Lionello Lunesu 2015-05-28 20:06:59 UTC
There are two solutions to this:

1. Make dchar.max == uint.max

2. Make dchar = uint use range checks to determine whether implicit cast is safe


ad 1. This changes dchar.max, but there doesn't appear to be much code depending on it. In fact, Phobos has a couple `if (d > 0x10FFFF)` which don't currently make sense.

ad 2. Generate warning/deprecation when the range falls outside 0..0x10FFFF. breaks some code that assembles a dchar from wchar/char, and fixed by adding casts.
Comment 2 thomas.bockman 2015-10-24 16:13:54 UTC
The issue of dchar.max versus uint.max has been discussed on the forums:
    http://forum.dlang.org/thread/qjmikijfluaniwnxhigp@forum.dlang.org

It was decided that D compilers must support dchar values which are outside the range of valid Unicode code points; otherwise handling encoding errors and the like gets very awkward. Besides, actually enforcing a range less than that which is actually representable by the binary format of dchar would be very difficult to do in a performant way.

In light of this, I think #1 (Make dchar.max == uint.max) is the correct solution. Allowing dchar.max to be less than its true maximum has probably caused subtle bugs in some generic code.

The value of the maximum code point (0x10FFFF) should be moved to a separate constant.
Comment 3 dlangBugzillaToGithub 2024-12-13 18:43:03 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17709

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB