www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20811] New: Regression as of 2.066.0 - CTFE static variable


          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 puremagic.com
          Reporter: destructionator gmail.com

Here's a fun one:

string bug() {
        char[1] counter = "0";
        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:

May 08 2020