Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ UT_MODULES:=$(patsubst src/%.d,$(ROOT)/unittest/%,$(SRCS))
HAS_ADDITIONAL_TESTS:=$(shell test -d test && echo 1)
ifeq ($(HAS_ADDITIONAL_TESTS),1)
ADDITIONAL_TESTS:=test/init_fini test/exceptions test/coverage test/profile test/cycles test/allocations test/typeinfo \
test/thread test/unittest test/imports
test/thread test/unittest test/imports test/betterc
ADDITIONAL_TESTS+=$(if $(SHARED),test/shared,)
endif

Expand Down
17 changes: 11 additions & 6 deletions src/object.d
Original file line number Diff line number Diff line change
Expand Up @@ -3027,14 +3027,19 @@ unittest
/// ditto
void destroy(T)(ref T obj) if (is(T == struct))
{
// We need to re-initialize `obj`. Previously, the code
// `auto init = cast(ubyte[])typeid(T).initializer()` was used, but
// `typeid` is a runtime call and requires the `TypeInfo` object which is
// not usable when compiling with -betterC. If we do `obj = T.init` then we
// end up needlessly calling postblits and destructors. So, we create a
// static immutable lvalue that can be re-used with subsequent calls to `destroy`
shared static immutable T init = T.init;

_destructRecurse(obj);
() @trusted {
auto buf = (cast(ubyte*) &obj)[0 .. T.sizeof];
auto init = cast(ubyte[])typeid(T).initializer();
if (init.ptr is null) // null ptr means initialize to 0s
buf[] = 0;
else
buf[] = init[];
auto dest = (cast(ubyte*) &obj)[0 .. T.sizeof];
auto src = (cast(ubyte*) &init)[0 .. T.sizeof];
dest[] = src[];
} ();
}

Expand Down
12 changes: 12 additions & 0 deletions test/betterc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include ../common.mak

TESTS:=test18828

.PHONY: all clean
all: $(addprefix $(ROOT)/,$(addsuffix ,$(TESTS)))

$(ROOT)/%: $(SRC)/%.d
$(QUIET)$(DMD) -betterC -c -of$@ $<

clean:
rm -rf $(ROOT)
10 changes: 10 additions & 0 deletions test/betterc/src/test18828.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*******************************************/
// https://issues.dlang.org/show_bug.cgi?id=18828

struct S18828 { }

void test18828()
{
S18828 s;
destroy(s);
}