[Issue 21868] New: DIP1000 doesn't catch pointer to struct temporary

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 27 09:34:21 UTC 2021


          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 at puremagic.com
          Reporter: moonlightsentinel at 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];

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


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


More information about the Digitalmars-d-bugs mailing list