[Issue 18792] Incorrect scope analysis with -dip1000 for small-sized-optimized string

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 4 11:08:43 UTC 2020


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

--- Comment #3 from Per Nordlöw <per.nordlow at gmail.com> ---
(In reply to Per Nordlöw from comment #2)
> Small enough, Walter?

Forgot to remove obselete comments. Here's a new version with irrelevant
comments removed.


struct SSOString
{
pure nothrow @nogc:

    inout(char)[] opSlice() inout return scope @trusted 
    {
        return small.data[0 .. small.length]; 
    }

    struct Small
    {
        ubyte length; 
        char[15] data;
    }

    struct Raw        
    {
        size_t length;
        char* ptr;
    }

    union
    {
        Raw raw; // PROBLEM this declaration prevents DIP-1000 scope analysis
from kicking in in `opSlice`
        Small small;
    }
}

@safe pure nothrow @nogc unittest
{
    char[] shouldFail1() @safe pure nothrow @nogc
    {
        SSOString x;
        return x[];             // TODO should fail with -dip1000
    }
}

--


More information about the Digitalmars-d-bugs mailing list