Skip to content

Commit

Permalink
fix Issue 17582 - Applying const to struct declaration should make th…
Browse files Browse the repository at this point in the history
…e struct type const
  • Loading branch information
WalterBright committed Jul 3, 2017
1 parent d7887fb commit 07452c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/ddmd/dstruct.d
Expand Up @@ -297,6 +297,8 @@ extern (C++) class StructDeclaration : AggregateDeclaration

if (this.errors)
type = Type.terror;
if (semanticRun == PASSinit)
type = type.addSTC(sc.stc | storage_class);
type = type.semantic(loc, sc);
if (type.ty == Tstruct && (cast(TypeStruct)type).sym != this)
{
Expand Down
12 changes: 9 additions & 3 deletions test/runnable/testconst.d
Expand Up @@ -2806,9 +2806,15 @@ void test6982()
/************************************/
// 7038

static assert(!is(S7038 == const));
static assert(is(S7038 == const));
const struct S7038{ int x; }
static assert(!is(S7038 == const));
static assert(is(S7038 == const));

shared struct S7038b{ int x; }
static assert(is(S7038b == shared));

immutable struct S7038c{ int x; }
static assert(is(S7038c == immutable));

static assert(!is(C7038 == const));
const class C7038{ int x; }
Expand All @@ -2817,7 +2823,7 @@ static assert(!is(C7038 == const));
void test7038()
{
S7038 s;
static assert(!is(typeof(s) == const));
static assert(is(typeof(s) == const));
static assert(is(typeof(s.x) == const int));

C7038 c;
Expand Down

0 comments on commit 07452c2

Please sign in to comment.