Skip to content

Commit

Permalink
Issue 6534 - const struct definition inside functions too
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Sep 25, 2012
1 parent 2625839 commit 0adbdc1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 31 deletions.
52 changes: 21 additions & 31 deletions src/parse.c
Expand Up @@ -183,13 +183,6 @@ Dsymbols *Parser::parseDeclDefs(int once)
break;
}

case TOKstruct:
case TOKunion:
case TOKclass:
case TOKinterface:
s = parseAggregate();
break;

case TOKimport:
s = parseImport(decldefs, 0);
break;
Expand Down Expand Up @@ -233,6 +226,10 @@ Dsymbols *Parser::parseDeclDefs(int once)
case TOKtypeof:
case TOKdot:
case TOKvector:
case TOKstruct:
case TOKunion:
case TOKclass:
case TOKinterface:
Ldeclaration:
a = parseDeclarations(STCundefined, NULL);
decldefs->append(a);
Expand Down Expand Up @@ -2853,12 +2850,22 @@ Dsymbols *Parser::parseDeclarations(StorageClass storage_class, unsigned char *c
return parseAutoDeclarations(storage_class, comment);
}

if (token.value == TOKclass)
if (token.value == TOKstruct ||
token.value == TOKunion ||
token.value == TOKclass ||
token.value == TOKinterface)
{
AggregateDeclaration *s = (AggregateDeclaration *)parseAggregate();
s->storage_class |= storage_class;
Dsymbol *s = parseAggregate();
Dsymbols *a = new Dsymbols();
a->push(s);

if (storage_class)
{
s = new StorageClassDeclaration(storage_class, a);
a = new Dsymbols();
a->push(s);
}

addComment(s, comment);
return a;
}
Expand Down Expand Up @@ -3566,16 +3573,6 @@ Statement *Parser::parseStatement(int flags)
condition = parseStaticIfCondition();
goto Lcondition;
}
if (t->value == TOKstruct || t->value == TOKunion || t->value == TOKclass)
{
nextToken();
Dsymbols *a = parseBlock();
Dsymbol *d = new StorageClassDeclaration(STCstatic, a);
s = new ExpStatement(loc, d);
if (flags & PSscope)
s = new ScopeStatement(loc, s);
break;
}
if (t->value == TOKimport)
{ nextToken();
Dsymbols *imports = new Dsymbols();
Expand Down Expand Up @@ -3616,6 +3613,10 @@ Statement *Parser::parseStatement(int flags)
case TOKgshared:
case TOKat:
#endif
case TOKstruct:
case TOKunion:
case TOKclass:
case TOKinterface:
Ldeclaration:
{ Dsymbols *a;

Expand Down Expand Up @@ -3644,17 +3645,6 @@ Statement *Parser::parseStatement(int flags)
break;
}

case TOKstruct:
case TOKunion:
case TOKclass:
case TOKinterface:
{ Dsymbol *d;

d = parseAggregate();
s = new ExpStatement(loc, d);
break;
}

case TOKenum:
{ /* Determine if this is a manifest constant declaration,
* or a conventional enum.
Expand Down
39 changes: 39 additions & 0 deletions test/compilable/test6534.d
@@ -0,0 +1,39 @@
void main()
{
class MC{ int x; }
const class CC{ int x; } static assert(is(typeof( CC.x) == const));
immutable class IC{ int x; } static assert(is(typeof( IC.x) == immutable));
shared class SC{ int x; } static assert(is(typeof( SC.x) == shared));
shared const class SCC{ int x; } static assert(is(typeof(SCC.x) == shared) && is(typeof(SCC.x) == const));

struct MS{ int x; }
const struct CS{ int x; } static assert(is(typeof( CS.x) == const));
immutable struct IS{ int x; } static assert(is(typeof( IS.x) == immutable));
shared struct SS{ int x; } static assert(is(typeof( SS.x) == shared));
shared const struct SCS{ int x; } static assert(is(typeof(SCS.x) == shared) && is(typeof(SCS.x) == const));

union MU{ int x; }
const union CU{ int x; } static assert(is(typeof( CU.x) == const));
immutable union IU{ int x; } static assert(is(typeof( IU.x) == immutable));
shared union SU{ int x; } static assert(is(typeof( SU.x) == shared));
shared const union SCU{ int x; } static assert(is(typeof(SCU.x) == shared) && is(typeof(SCU.x) == const));


static class S_MC{ int x; }
const static class S_CC{ int x; } static assert(is(typeof( S_CC.x) == const));
immutable static class S_IC{ int x; } static assert(is(typeof( S_IC.x) == immutable));
shared static class S_SC{ int x; } static assert(is(typeof( S_SC.x) == shared));
shared const static class S_SCC{ int x; } static assert(is(typeof(S_SCC.x) == shared) && is(typeof(S_SCC.x) == const));

static struct S_MS{ int x; }
const static struct S_CS{ int x; } static assert(is(typeof( S_CS.x) == const));
immutable static struct S_IS{ int x; } static assert(is(typeof( S_IS.x) == immutable));
shared static struct S_SS{ int x; } static assert(is(typeof( S_SS.x) == shared));
shared const static struct S_SCS{ int x; } static assert(is(typeof(S_SCS.x) == shared) && is(typeof(S_SCS.x) == const));

static union S_MU{ int x; }
const static union S_CU{ int x; } static assert(is(typeof( S_CU.x) == const));
immutable static union S_IU{ int x; } static assert(is(typeof( S_IU.x) == immutable));
shared static union S_SU{ int x; } static assert(is(typeof( S_SU.x) == shared));
shared const static union S_SCU{ int x; } static assert(is(typeof(S_SCU.x) == shared) && is(typeof(S_SCU.x) == const));
}

0 comments on commit 0adbdc1

Please sign in to comment.