D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20021 - `static if` doesn't evaluate `opCast(T : bool)`
Summary: `static if` doesn't evaluate `opCast(T : bool)`
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 regression
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2019-07-02 10:17 UTC by ag0aep6g
Modified: 2019-08-25 21:26 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 ag0aep6g 2019-07-02 10:17:23 UTC
Should compile:

----
struct S
{
    bool opCast(T : bool)() { return true; }
}

void main()
{
    static if (S.init) {} /* Error: expression (S).init of type S does not have a boolean value */
    static if (!!S.init) {} /* no error */
    if (S.init) {} /* no error */
}
----
Comment 1 Dlang Bot 2019-07-28 22:42:29 UTC
@dkorpel created dlang/dmd pull request #10237 "Fix issue 20021 - static if doesn't evaluate opCast(bool)" fixing this issue:

- fix issue 20021 - static if doesn't evaluate opCast(bool)

https://github.com/dlang/dmd/pull/10237
Comment 2 elpenguino+D 2019-08-20 02:21:18 UTC
The second case causes an error as well in DMD 2.088.0-beta.1. This is a partial regression now.
Comment 3 Dlang Bot 2019-08-20 09:14:52 UTC
@aG0aep6G created dlang/dmd pull request #10324 "fix issue 20021 - static if doesn't evaluate opCast(bool) " fixing this issue:

- fix issue 20021 - static if doesn't evaluate opCast(bool)

https://github.com/dlang/dmd/pull/10324
Comment 4 Dlang Bot 2019-08-20 10:53:14 UTC
dlang/dmd pull request #10324 "fix issue 20021 - static if doesn't evaluate opCast(bool) " was merged into stable:

- 98cab64efd160365bde1bcc1b7230cc92e58ced1 by dkorpel:
  fix issue 20021 - static if doesn't evaluate opCast(bool)

https://github.com/dlang/dmd/pull/10324
Comment 5 Dlang Bot 2019-08-25 21:26:23 UTC
dlang/dmd pull request #10348 "Merge remote-tracking branch 'upstream/stable' into merge_stable" was merged into master:

- 421e9ce137c6aff941ebde92863c53292226a0b3 by aG0aep6G:
  fix issue 20021 - static if doesn't evaluate opCast(bool)  (#10324)
  
  fix issue 20021 - static if doesn't evaluate opCast(bool) 
  merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>

https://github.com/dlang/dmd/pull/10348