Browse files

Merge pull request #1829 from 9rnsr/fix9773

Issue 9773 - ref parameter with default string literal should not compile
  • Loading branch information...
2 parents 669855c + 706b187 commit 630e484c7e20cb156bf71404a342a8b98459cfde @WalterBright WalterBright committed Apr 4, 2013
Showing with 15 additions and 11 deletions.
  1. +5 −11 src/expression.c
  2. +10 −0 test/fail_compilation/fail9773.d
View
16 src/expression.c
@@ -1208,14 +1208,7 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
}
if (p->storageClass & STCref)
{
- if (arg->op == TOKslice
- && p->type->toBasetype()->ty == Tsarray) // Workaround for bug 2486
- {
- arg = arg->castTo(sc, p->type);
- arg = arg->toLvalue(sc, arg);
- }
- else
- arg = arg->toLvalue(sc, arg);
+ arg = arg->toLvalue(sc, arg);
}
else if (p->storageClass & STCout)
{
@@ -3744,13 +3737,14 @@ int StringExp::isLvalue()
/* string literal is rvalue in default, but
* conversion to reference of static array is only allowed.
*/
- return 0;
+ return (type && type->toBasetype()->ty == Tsarray);
}
Expression *StringExp::toLvalue(Scope *sc, Expression *e)
{
- //printf("StringExp::toLvalue(%s)\n", toChars());
- return this;
+ //printf("StringExp::toLvalue(%s) type = %s\n", toChars(), type ? type->toChars() : NULL);
+ return (type && type->toBasetype()->ty == Tsarray)
+ ? this : Expression::toLvalue(sc, e);
}
Expression *StringExp::modifiableLvalue(Scope *sc, Expression *e)
View
10 test/fail_compilation/fail9773.d
@@ -0,0 +1,10 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/fail9773.d(8): Error: "" is not an lvalue
+---
+*/
+void f(ref string a = "")
+{
+ a = "crash and burn";
+}

0 comments on commit 630e484

Please sign in to comment.