Bug 10842 – Some integer casts wrongly remove side-effect of the operand.
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-17T18:28:00Z
Last change time
2013-10-08T20:55:44Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
thelastmammoth
Comments
Comment #0 by thelastmammoth — 2013-08-17T18:28:51Z
dmd -version=A -run main.d: prints nothing
dmd -version=B -run main.d: prints ok
----
auto fail(){
import std.stdio;
writeln("ok");
/+
//would be same with this:
assert(0);
//or this:
import std.exception; throw new Exception("bad");
+/
return null;
}
string foo(){
version(A){
auto temp=fail();
return temp;
}
else
return fail();
}
void main(){
foo();
}
Comment #1 by andrej.mitrovich — 2013-08-17T18:40:12Z
Reduced:
-----
auto ret1()
{
assert(0); // should throw, doesn't
return null;
}
string test1()
{
return ret1();
}
void main()
{
test1();
}
-----
If you change the return to an explicit expression, e.g. `return ""`, then the assert is triggered.
Also perhaps noteworthy is that in older releases the reduced code used to fail to compile, e.g. in 2.057:
Error: e2ir: cannot cast ret1() of type typeof(null) to type string
Comment #2 by thelastmammoth — 2013-08-17T18:58:29Z
> If you change the return to an explicit expression, e.g. `return ""`, then the
> assert is triggered.
In my case I want to make it work with arbitrary types, not just strings, do you have a suggestion for this?
(
I just posted a suggestion here:
http://forum.dlang.org/thread/[email protected]
"how to get enclosing function as symbol ? (eg: __function__.stringof ==__FUNCTION__)"
which would allow this among other things.
)
Comment #3 by andrej.mitrovich — 2013-08-17T19:09:05Z
(In reply to comment #2)
> Reduced:
Actually the bug is unrelated to auto, but instead related to typeof(null):
-----
typeof(null) ret1()
{
assert(0); // not thrown
return null;
}
string test1()
{
return ret1();
}
void main()
{
test1();
}
-----