[Issue 20811] New: Regression as of 2.066.0 - CTFE static variable retained across calls
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri May 8 18:08:55 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20811
Issue ID: 20811
Summary: Regression as of 2.066.0 - CTFE static variable
retained across calls
Product: D
Version: D2
Hardware: x86_64
OS: All
Status: NEW
Keywords: CTFE, wrong-code
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: destructionator at gmail.com
Here's a fun one:
string bug() {
char[1] counter = "0";
counter[$-1]++;
return counter.dup;
}
pragma(msg, bug());
pragma(msg, bug());
pragma(msg, bug());
pragma(msg, bug());
Each call returns something different; the counter variable is apparently
retained between calls.
And if you call bug() at runtime after that, it retains the last counter. Add
this in:
void main() {
assert(bug == "5");
assert(bug == "5");
assert(bug == "5");
assert(bug == "5");
}
and it passes! Unless you change the msgs lolol.
Same behavior on Windows and Linux.
I almost didn't want to report this because having a compile-time counter like
this can actually be pretty useful! But it is also obviously wrong.
History output:
Random error prior to 63. Worked correctly between 63 and 65, then
2.066.0: Status -6 with output: dmd: interpret.c:4025: void
Interpreter::interpretAssignCommon(BinExp*, Expression* (*)(Type*, Expression*,
Expression*), int): Assertion `newval->op == TOKarrayliteral' failed.
2.067.1 to 2.071.2: Failure with output:
-----
1
2
3
4
--
More information about the Digitalmars-d-bugs
mailing list