From 287ea89167e8753f701a5235c53a47431a179636 Mon Sep 17 00:00:00 2001 From: Don Clugston Date: Wed, 20 Mar 2013 13:18:56 +0100 Subject: [PATCH] Allow string literals to be cast to mutable It is legal in constfolding, and it's already impossible to modify a string literal in CTFE. --- src/interpret.c | 4 ++-- test/compilable/interpret3.d | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interpret.c b/src/interpret.c index 93aa65b39fb9..31cb37f6897a 100644 --- a/src/interpret.c +++ b/src/interpret.c @@ -1426,11 +1426,11 @@ Expression *StringExp::interpret(InterState *istate, CtfeGoal goal) * In D2, we also disallow casts of read-only literals to mutable, * though it isn't strictly necessary. */ -#if DMDV2 +#if 0 //DMDV2 // Fixed-length char arrays always get duped later anyway. if (type->ty == Tsarray) return this; - if (!(((TypeNext *)type)->next->mod & (MODconst | MODimmutable))) + if (!(((TypeNext *)type)->next->toBasetype()->mod & (MODconst | MODimmutable))) { // It seems this happens only when there has been an explicit cast error("cannot cast a read-only string literal to mutable in CTFE"); return EXP_CANT_INTERPRET; diff --git a/test/compilable/interpret3.d b/test/compilable/interpret3.d index 5c973f68a3b8..110f56b415b5 100644 --- a/test/compilable/interpret3.d +++ b/test/compilable/interpret3.d @@ -1267,7 +1267,7 @@ static assert(!is(typeof(compiles!(zfs(2))))); static assert(!is(typeof(compiles!(zfs(3))))); static assert(!is(typeof(compiles!(zfs(4))))); static assert(is(typeof(compiles!(zfs(1))))); -static assert(!is(typeof(compiles!(zfs(5))))); +static assert(is(typeof(compiles!(zfs(5))))); /************************************************** .dup must protect string literals