[Issue 12625] New: implicit slicing of RValue static array should be illegal

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Apr 23 04:24:26 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12625

          Issue ID: 12625
           Summary: implicit slicing of RValue static array should be
                    illegal
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: monarchdodra at gmail.com

This will compile without a single warning:

//----
    int[1] foo();
    int[] a = foo();
//----

It's wrong, because we are obtaining a slice to temporary data.

This isn't even a question of escape analysis or anything like that. It's
really just  nothing more than (basically) taking the address of a temporary,
which is pretty much wrong 100% of the time, and never correct.

I've been hit by it several times. I've fixed and seen the bug in phobos. It's
come up regularly in phobos learn.

Without entirelly putting into question the implicit slicing of static arrays,
can we *please* at least patch this specific use case?

The *only* code this *can* break (and *will* break) is code that is certifiably
worng.

--


More information about the Digitalmars-d-bugs mailing list