Bug 17716 – wrong result of IsExpression when not in static assert

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-08-03T17:26:04Z
Last change time
2024-12-13T18:53:48Z
Assigned to
No Owner
Creator
ag0aep6g
Moved to GitHub: dmd#19295 →

Comments

Comment #0 by ag0aep6g — 2017-08-03T17:26:04Z
---- struct S { shared int* foo; int* bar; } static assert(!is(shared S : S)); /* passes */ pragma(msg, is(shared S : S)); /* "true" */ static if (is(shared S : S)) { static assert(false); /* is triggered */ } ---- The `static assert` is correct. The `pragma(msg, ...);` should print "false": The body of the `static if` should not be entered. Also happens with other qualifiers (const, immutable). Depends on the order of the struct fields. When the unqualified fields comes first, everything works as expected.
Comment #1 by ag0aep6g — 2017-08-03T17:55:50Z
Inside functions everything works as expected: ---- struct S { shared int* foo; int* bar; } pragma(msg, is(shared S : S)); /* "true" - wrong */ void f() { pragma(msg, is(shared S : S)); /* "false" - correct */ } ----
Comment #2 by er.krali — 2018-09-19T15:26:13Z
Furthermore, it doesn't work with ref parameters either: --- struct S { int i; } void fun(ref S s, int i) { s.i = i; } void main() { shared S s; /* This fails: onlineapp.d(17): Error: function onlineapp.fun(ref S s, int i) is not callable using argument types (S, int) onlineapp.d(17): cannot pass rvalue argument cast(S)s of type S to parameter ref S s fun(cast(S) s, 1); */ (*(cast (S*) &s)).fun(1); // Nasty workaround assert (s.i == 1); } --- I also can't understand why the workaround works at all, the result of dereferencing a pointer should surely be a rvalue? Is that also a bug?
Comment #3 by ag0aep6g — 2018-09-19T16:41:57Z
(In reply to er.krali from comment #2) > Furthermore, it doesn't work with ref parameters either: [...] You made the same comment on issue 17729, and it makes more sense there. I guess you posted it here by accident?
Comment #4 by er.krali — 2018-09-19T16:44:39Z
(In reply to ag0aep6g from comment #3) > > You made the same comment on issue 17729, and it makes more sense there. I > guess you posted it here by accident? Yes I did, I didn't notice that bugzilla had moved to the "next" bug and I thought it hadn't been posted. If there's a way to remove it (and this comment, if needed), please do, I don't think I can do it myself.
Comment #5 by robert.schadek — 2024-12-13T18:53:48Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19295 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB