http://bugzilla.gdcproject.org/show_bug.cgi?id=211
Bug ID: 211 Summary: Error: iteration 2305843009213693951 invokes undefined behavior Product: GDC Version: development Hardware: All OS: All Status: NEW Severity: normal Priority: Normal Component: gdc Assignee: ibuc...@gdcproject.org Reporter: ibuc...@gdcproject.org --- struct Array { void setlength(size_t nlength) { foreach (ref val; ptr[nlength .. length]) val = 0; } void insertBack() { setlength(length + 1); } size_t* ptr; size_t length; } --- This causes an warning/error to be emitted under optimizations. (-O2 -Werror) --- array.d: In function ‘insertBack’: array.d:5:9: error: iteration 2305843009213693951 invokes undefined behavior [-Werror=aggressive-loop-optimizations] foreach (ref val; ptr[nlength .. length]) ^ array.d:5:9: note: within this loop foreach (ref val; ptr[nlength .. length]) ^ --- This is the codegen: --- while (1) { ulong & val; if (!(__aggr40.length > __key41)) break; val = __aggr40.ptr + __key41 * 8; *val = 0; __key41 = __key41 + 1; } --- I think this could be vastly improved by initializing the reference directly, rather than via a modify expression. -- You are receiving this mail because: You are watching all bug changes.