[Issue 15302] New: DMD -O optimizing out meaningful code
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Nov 8 07:50:20 PST 2015
https://issues.dlang.org/show_bug.cgi?id=15302
Issue ID: 15302
Summary: DMD -O optimizing out meaningful code
Product: D
Version: D2
Hardware: x86
OS: All
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ketmar at ketmar.no-ip.org
compiling the following code with "dmd -O" leading to failed assert. seems that
dmd optimized out "lineNumber++;", failing to see that it is used in "catch"
part.
===
class XException : Exception {
this (string msg, size_t lineNumber, string file=__FILE__, size_t
line=__LINE__, Throwable next=null) pure nothrow @safe {
super(msg, file, line, next);
_lineNumber = lineNumber;
}
@nogc @safe size_t lineNumber() const nothrow {
return _lineNumber;
}
private:
size_t _lineNumber;
}
void foo (string[] lines) {
size_t lineNumber = 0;
try {
foreach (line; lines) {
lineNumber++;
if (line == "Line3") throw new Exception("!");
}
} catch (Exception e) {
throw new XException(e.msg, lineNumber, e.file, e.line, e.next);
}
}
void main () {
try {
foo(["Line", "AnotherLine", "Line3"]);
} catch (XException e) {
assert(e.lineNumber == 3);
}
}
--
More information about the Digitalmars-d-bugs
mailing list