Skip to content

Commit

Permalink
Allow string literals to be cast to mutable
Browse files Browse the repository at this point in the history
It is legal in constfolding, and it's already impossible
to modify a string literal in CTFE.
  • Loading branch information
don-clugston-sociomantic committed Mar 26, 2013
1 parent 299c0f7 commit 287ea89
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/interpret.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/compilable/interpret3.d
Expand Up @@ -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
Expand Down

0 comments on commit 287ea89

Please sign in to comment.