www.digitalmars.com         C & C++   DMDScript  

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


          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 ////////////////

struct Shape
    immutable size_t[] dims = [];

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


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

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 2021