www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21868] New: DIP1000 doesn't catch pointer to struct temporary

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

          Issue ID: 21868
           Summary: DIP1000 doesn't catch pointer to struct temporary
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: moonlightsentinel disroot.org

Reduced example from TempCString in Phobos:

=======================================================================
char* foo(string s)  safe
{
    // Previously used via `alias this`
    char* p = tempCString(s).ptr;

    // Also works
    TempCStringBuffer res;
    p = res.ptr;

    return p;
}

TempCStringBuffer tempCString(scope string str)  safe;

struct TempCStringBuffer
{
    char* ptr() return scope  safe
    {
        return &_buff[0];
    }

private:
    char* _ptr;     // <= Required
    char[256] _buff;
}

=======================================================================

Note that DMD reports the correct error when the unused `_ptr` is absent.

--
Apr 27