From 9f7b2f8cfe5d7482f2de7f9678c176d54abe237f Mon Sep 17 00:00:00 2001 From: Don Clugston Date: Tue, 1 Mar 2011 08:14:03 +0100 Subject: [PATCH 1/3] 3581 "private" attribute breaks "override" It's slightly more general than in the bug report: any non-virtual function cannot use override. --- src/func.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/func.c b/src/func.c index e3184770bc2e..3deabe86065e 100644 --- a/src/func.c +++ b/src/func.c @@ -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"); From 66c8899377b21b07979a80ec761326dcaa738634 Mon Sep 17 00:00:00 2001 From: Don Clugston Date: Fri, 18 Mar 2011 16:52:48 +0100 Subject: [PATCH 2/3] 5722 Regression(2.052): Appending code-unit from multi-unit code point at compile time gives wrong result This was caused by an incorrect fix to bug 4389. Concatenation needs to be treated differently if it is a homogonenous concatentation (char[]~char, wchar[]~char, dchar[]~dchar) compared to hetero concatenation (eg, char[]~dchar). Homo-concatenation should just use a simple append, ramming the bytes together; hetero needs to do a UTF conversion before appending. Originally simple append was used all the time; this was bug 4389. After the fix it used conversion all the time, causing this regression. --- src/constfold.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/constfold.c b/src/constfold.c index ac1ef0104218..0917ed5a35e3 100644 --- a/src/constfold.c +++ b/src/constfold.c @@ -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); @@ -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); From ab5b3431add4a47457b404388092d735430cfc0d Mon Sep 17 00:00:00 2001 From: Don Clugston Date: Fri, 18 Mar 2011 16:59:05 +0100 Subject: [PATCH 3/3] Test cases for bug 5722. --- test/compilable/interpret3.d | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/compilable/interpret3.d b/test/compilable/interpret3.d index 38bfed48e744..3cc5327142f3 100644 --- a/test/compilable/interpret3.d +++ b/test/compilable/interpret3.d @@ -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 );