diff --git a/src/hdrgen.c b/src/hdrgen.c
index 74c029f..19e6b94 100644
--- a/src/hdrgen.c
+++ b/src/hdrgen.c
@@ -547,6 +547,18 @@ public:
     void visit(WithStatement *s)
     {
         buf->writestring("with (");
+        if (Parameter *a = s->arg)
+        {
+            StorageClass stc = a->storageClass;
+            if (!a->type && !stc)
+                stc = STCauto;
+            StorageClassDeclaration::stcToCBuffer(buf, stc);
+            if (a->type)
+                typeToBuffer(a->type, a->ident);
+            else
+                buf->writestring(a->ident->toChars());
+            buf->writestring(" = ");
+        }
         s->exp->accept(this);
         buf->writestring(")");
         buf->writenl();
diff --git a/src/parse.c b/src/parse.c
index 0dc44a6..58244f5 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -5220,15 +5220,37 @@ Statement *Parser::parseStatement(int flags, const utf8_t** endPtr)
         }
 
         case TOKwith:
-        {   Expression *exp;
+        {
             Statement *body;
+            Expression *exp = NULL;
+            Parameter *arg = NULL;
 
             nextToken();
             check(TOKlparen);
+
+            StorageClass storageClass = parseStorageClass();
+
+            if (storageClass != 0 &&
+                token.value == TOKidentifier &&
+                peek(&token)->value == TOKassign)
+            {
+                Identifier *ai = token.ident;
+                Type *at = NULL;        // infer argument type
+                nextToken();
+                check(TOKassign);
+                arg = new Parameter(storageClass, at, ai, NULL);
+            }
+            else if (isDeclaration(&token, 2, TOKassign, NULL))
+            {
+                Identifier *ai;
+                Type *at = parseType(&ai);
+                check(TOKassign);
+                arg = new Parameter(storageClass, at, ai, NULL);
+            }
             exp = parseExpression();
             check(TOKrparen);
             body = parseStatement(PSscope);
-            s = new WithStatement(loc, exp, body);
+            s = new WithStatement(loc, arg, exp, body);
             break;
         }
 
diff --git a/src/statement.c b/src/statement.c
index a7c257c..f5898ee 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -4161,9 +4161,10 @@ bool SynchronizedStatement::hasContinue()
 
 /******************************** WithStatement ***************************/
 
-WithStatement::WithStatement(Loc loc, Expression *exp, Statement *body)
+WithStatement::WithStatement(Loc loc, Parameter *arg, Expression *exp, Statement *body)
     : Statement(loc)
 {
+    this->arg = arg;
     this->exp = exp;
     this->body = body;
     wthis = NULL;
@@ -4172,6 +4173,7 @@ WithStatement::WithStatement(Loc loc, Expression *exp, Statement *body)
 Statement *WithStatement::syntaxCopy()
 {
     return new WithStatement(loc,
+        arg ? arg->syntaxCopy() : NULL,
         exp->syntaxCopy(),
         body ? body->syntaxCopy() : NULL);
 }
@@ -4182,6 +4184,29 @@ Statement *WithStatement::semantic(Scope *sc)
     Initializer *init;
 
     //printf("WithStatement::semantic()\n");
+
+    if (arg)
+    {
+        /* Re-write to
+         * {
+         *   <decl> argname = exp
+         *   with(argname)
+         *   {
+         *     ...
+         *   }
+         * }
+         */
+        //printf("WITH arg(%s)\n", arg->ident->toChars());
+        wthis = new VarDeclaration(loc, arg->type, arg->ident, new ExpInitializer(loc, exp));
+        wthis->parent = sc->func;
+        wthis->storage_class |= arg->storageClass;
+        ExpStatement *es = new ExpStatement(loc, new DeclarationExp(loc, wthis));
+        exp = new VarExp(loc, wthis);
+        Statement *ss = new ScopeStatement(loc, new CompoundStatement(loc, es, this));
+        arg = NULL; // prevent further rewritings
+        return ss->semantic(sc);
+    }
+
     exp = exp->semantic(sc);
     exp = resolveProperties(sc, exp);
     // exp = exp_>optimize(0);  //?
diff --git a/src/statement.h b/src/statement.h
index 7e9c716..d27f6be 100644
--- a/src/statement.h
+++ b/src/statement.h
@@ -574,11 +574,12 @@ public:
 class WithStatement : public Statement
 {
 public:
+    Parameter *arg;
     Expression *exp;
     Statement *body;
     VarDeclaration *wthis;
 
-    WithStatement(Loc loc, Expression *exp, Statement *body);
+    WithStatement(Loc loc, Parameter *arg, Expression *exp, Statement *body);
     Statement *syntaxCopy();
     Statement *semantic(Scope *sc);
 
