www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21928] New: Wrong location for "array literal in nogc

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

          Issue ID: 21928
           Summary: Wrong location for "array literal in  nogc function
                    main may cause GC allocation" error
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

//////////////// test.d ////////////////
 nogc:

struct Shape
{
    immutable size_t[] dims = [];
}

void main()
{
    auto s = Shape(2 ~ Shape.init.dims);
}
////////////////////////////////////////

Output:

test.d(3): Error: array literal in  nogc function D main may cause a GC
allocation

Seems to be a particularly bad variant of issue 21871. It misleadingly places
the blame on the initializer as if it is causing a GC allocation. Instead, the
error should be placed at the ~ operator.

--
May 18