Skip to content
Closed
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
19 changes: 14 additions & 5 deletions src/constfold.c
Original file line number Diff line number Diff line change
Expand Up @@ -1372,10 +1372,12 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
int sz = t->size();

dinteger_t v = e->toInteger();

size_t len = utf_codeLength(sz, v);
size_t len = (t->ty == tn->ty) ? 1 : utf_codeLength(sz, v);
s = mem.malloc((len + 1) * sz);
utf_encode(sz, s, v);
if (t->ty == tn->ty)
memcpy((unsigned char *)s, &v, sz);
else
utf_encode(sz, s, v);

// Add terminating 0
memset((unsigned char *)s + len * sz, 0, sz);
Expand Down Expand Up @@ -1468,10 +1470,17 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
int sz = es1->sz;
dinteger_t v = e2->toInteger();

size_t len = es1->len + utf_codeLength(sz, v);
// Is it a concatentation of homogenous types?
// (char[] ~ char, wchar[]~wchar, or dchar[]~dchar)
bool homoConcat = (sz == t2->size());
size_t len = es1->len;
len += homoConcat ? 1 : utf_codeLength(sz, v);
s = mem.malloc((len + 1) * sz);
memcpy(s, es1->string, es1->len * sz);
utf_encode(sz, (unsigned char *)s + (sz * es1->len), v);
if (homoConcat)
memcpy((unsigned char *)s + (sz * es1->len), &v, sz);
else
utf_encode(sz, (unsigned char *)s + (sz * es1->len), v);

// Add terminating 0
memset((unsigned char *)s + len * sz, 0, sz);
Expand Down
3 changes: 3 additions & 0 deletions src/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ void FuncDeclaration::semantic(Scope *sc)
if (isAbstract() && !isVirtual())
error("non-virtual functions cannot be abstract");

if (isOverride() && !isVirtual())
error("cannot override a non-virtual function");

if ((f->isConst() || f->isImmutable()) && !isThis())
error("without 'this' cannot be const/immutable");

Expand Down
7 changes: 7 additions & 0 deletions test/compilable/interpret3.d
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,10 @@ size_t bug5524(int x, int[] more...)
}

static assert(bug5524(3) == 10);

// 5722

static assert( ("" ~ "\©"[0]).length == 1 );
const char[] null5722 = null;
static assert( (null5722 ~ "\©"[0]).length == 1 );
static assert( ("\©"[0] ~ null5722).length == 1 );