Bug 16464 – opCast doco is insufficient

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-09-02T11:11:00Z
Last change time
2016-10-01T11:45:58Z
Keywords
pull, spec
Assigned to
nobody
Creator
turkeyman

Comments

Comment #0 by turkeyman — 2016-09-02T11:11:41Z
opCast doco is not very helpful: http://dlang.org/spec/operatoroverloading.html#cast This says something about 'bool', but nothing about any other type. When is the cast operator invoked? What circumstances will it be used? Is opCast only explicit, or will it be used for implicit casts? What happens if the src has an opCast, and the target type has a constructor that receives the src type? In that situation, when will the opCast be used, and when will the constructor be used?
Comment #1 by schveiguy — 2016-09-02T12:50:50Z
The table does say, cast(T)u is rewritten to u.opCast!(T)() Probably could be spelled out better to indicate that's the ONLY case where opCast is used (aside from the boolean for if clauses)
Comment #2 by turkeyman — 2016-09-02T12:55:15Z
Wow, you're right. I didn't make any sense of that table at all. Compare that table to the table of binary operators immediately below. That inconsistency possibly lead me to overlook that table as noise. Anyway, I don't think it's well expressed when I couldn't see it right in front of my face! ;)
Comment #3 by schveiguy — 2016-09-02T13:27:21Z
(In reply to Manu from comment #2) > Compare that table to the table of binary operators immediately below. Compare that to the table of slice operators above :) I think actually, the table is a very obscure way to explain the rewrite, even when it's consistent with some of the other tables. I'll submit a strawman PR.
Comment #4 by schveiguy — 2016-09-02T13:33:09Z
Comment #5 by github-bugzilla — 2016-09-06T20:41:19Z
Commits pushed to master at https://github.com/dlang/dlang.org https://github.com/dlang/dlang.org/commit/9fdba00fb38984e76ebe4c26f392d03692917b72 Fix issue 16464. Define more clearly opCast usage https://github.com/dlang/dlang.org/commit/5af0f724bc85a06168ed7c7707a9d6249e8a582a Merge pull request #1467 from schveiguy/patch-4 Fix issue 16464. Define more clearly opCast usage
Comment #6 by github-bugzilla — 2016-10-01T11:45:58Z