Showing with 27 additions and 4 deletions.
  1. +13 −4 src/parse.d
  2. +14 −0 test/compilable/compile1.d
17 changes: 13 additions & 4 deletions src/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -4456,7 +4456,10 @@ public:
case TOKdot:
case TOKtypeof:
case TOKvector:
if (isDeclaration(&token, 2, TOKreserved, null))
/* Bugzilla 15163: If tokens can be handled as
* old C-style declaration or D expression, prefer the latter.
*/
if (isDeclaration(&token, 3, TOKreserved, null))
goto Ldeclaration;
else
goto Lexp;
Expand Down Expand Up @@ -5714,6 +5717,7 @@ public:
* needId 0 no identifier
* 1 identifier optional
* 2 must have identifier
* 3 must have identifier, but don't recognize old C-style syntax.
* Output:
* if *pt is not NULL, it is set to the ending token, which would be endtok
*/
Expand All @@ -5740,9 +5744,9 @@ public:
{
goto Lisnot;
}
if (!isDeclarator(&t, &haveId, &haveTpl, endtok))
if (!isDeclarator(&t, &haveId, &haveTpl, endtok, needId != 3))
goto Lisnot;
if (needId == 1 || (needId == 0 && !haveId) || (needId == 2 && haveId))
if (needId == 1 || (needId == 0 && !haveId) || ((needId == 2 || needId == 3) && haveId))
{
if (pt)
*pt = t;
Expand Down Expand Up @@ -5920,7 +5924,7 @@ public:
return false;
}

bool isDeclarator(Token** pt, int* haveId, int* haveTpl, TOK endtok)
bool isDeclarator(Token** pt, int* haveId, int* haveTpl, TOK endtok, bool allowAltSyntax = true)
{
// This code parallels parseDeclarator()
Token* t = *pt;
Expand Down Expand Up @@ -5989,10 +5993,15 @@ public:
*haveId = true;
t = peek(t);
break;

case TOKlparen:
if (!allowAltSyntax)
return false; // Do not recognize C-style declarations.

t = peek(t);
if (t.value == TOKrparen)
return false; // () is not a declarator

/* Regard ( identifier ) as not a declarator
* BUG: what about ( *identifier ) in
* f(*p)(x);
Expand Down
14 changes: 14 additions & 0 deletions test/compilable/compile1.d
Original file line number Diff line number Diff line change
Expand Up @@ -915,3 +915,17 @@ void test14388()
* and the second instantiation had created the AST duplication.
*/
}

/***************************************************/
// 15163

void function() func15164(int[] arr)
{
return () { };
}

void test15163()
{
auto arr = [[0]];
func15164(arr[0])();
}