Bug 6506 – OS X: wrong value is passed to simple argument along with a delegate with -O
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-08-16T10:58:00Z
Last change time
2011-08-16T18:50:20Z
Keywords
wrong-code
Assigned to
nobody
Creator
kennytm
Comments
Comment #0 by kennytm — 2011-08-16T10:58:09Z
----------------------------
void enforce6506(bool condition, lazy int m) {
assert(!condition);
}
void toImpl6506(int value) {
enforce6506(value >= 0, 4);
}
void bug6506() {
toImpl6506(-112345);
}
void main() { bug6506(); }
----------------------------
$ dmd -unittest -release -O z.d
$ ./z
core.exception.AssertError@z(2): Assertion failure
...
----------------------------
The bug _does_not_ appear when:
- one of '-unittest', '-release', and '-O' doesn't exist.
- the type of 'condition' is not 'bool', 'u?(byte|short|int)' and '[wd]?char'.
- the 'lazy' argument doesn't exist.
This bug is preventing OS X from passing Phobos' unit test in the release build after fixing bug 6377. See also https://github.com/D-Programming-Language/phobos/commit/994d76fe.
Comment #1 by kennytm — 2011-08-16T11:50:31Z
Correction:
1. Only -O is needed.
2. It's not 'lazy' causing the bug, but passing a nested delegate.
-------------------------------
void enforce6506b(bool condition, void delegate() m) {
assert(!condition);
}
void toImpl6506b(int value) {
void f(){}
enforce6506b(value >= 0, &f);
}
void bug6506b() {
toImpl6506b(-112345);
}
void main() { bug6506b(); }
-------------------------------
$ dmd -O z.d
$ ./z
core.exception.AssertError@z(2): Assertion failure
...
-------------------------------