Skip to content

Commit

Permalink
fix Issue 14416 - .sizeof yields 1 for uninstantiated struct templates
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Apr 6, 2015
1 parent 67675a5 commit 4d216e8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/expression.c
Expand Up @@ -7159,13 +7159,15 @@ Expression *DotIdExp::semanticX(Scope *sc)
e1 = resolvePropertiesX(sc, e1);
}
if (e1->op == TOKtuple && ident == Id::offsetof)
{ /* 'distribute' the .offsetof to each of the tuple elements.
{
/* 'distribute' the .offsetof to each of the tuple elements.
*/
TupleExp *te = (TupleExp *)e1;
Expressions *exps = new Expressions();
exps->setDim(te->exps->dim);
for (size_t i = 0; i < exps->dim; i++)
{ Expression *e = (*te->exps)[i];
{
Expression *e = (*te->exps)[i];
e = e->semantic(sc);
e = new DotIdExp(e->loc, e, Id::offsetof);
(*exps)[i] = e;
Expand All @@ -7175,7 +7177,6 @@ Expression *DotIdExp::semanticX(Scope *sc)
e = e->semantic(sc);
return e;
}

if (e1->op == TOKtuple && ident == Id::length)
{
TupleExp *te = (TupleExp *)e1;
Expand All @@ -7184,15 +7185,16 @@ Expression *DotIdExp::semanticX(Scope *sc)
return e;
}

if (e1->op == TOKdottd)
// Bugzilla 14416: Template has no built-in properties except for 'stringof'.
if ((e1->op == TOKdottd || e1->op == TOKtemplate) && ident != Id::stringof)
{
error("template %s does not have property %s", e1->toChars(), ident->toChars());
error("template %s does not have property '%s'", e1->toChars(), ident->toChars());
return new ErrorExp();
}

if (!e1->type)
{
error("expression %s does not have property %s", e1->toChars(), ident->toChars());
error("expression %s does not have property '%s'", e1->toChars(), ident->toChars());
return new ErrorExp();
}

Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/diag10089.d
Expand Up @@ -2,7 +2,7 @@
TEST_OUTPUT:
---
fail_compilation/diag10089.d(15): Error: undefined identifier 'chunks' in package 'imports'
fail_compilation/diag10089.d(17): Error: no property 'chunks' for type 'void'
fail_compilation/diag10089.d(17): Error: template Foo() does not have property 'chunks'
---
*/

Expand Down
13 changes: 13 additions & 0 deletions test/fail_compilation/fail14416.d
@@ -0,0 +1,13 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail14416.d(13): Error: template S(T) does not have property 'sizeof'
---
*/

struct S(T)
{
int x;
}

enum n = S.sizeof;
2 changes: 1 addition & 1 deletion test/fail_compilation/fail36.d
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail36.d(13): Error: no property 'a' for type 'void'
fail_compilation/fail36.d(13): Error: template t(int L) does not have property 'a'
fail_compilation/fail36.d(18): Error: mixin fail36.func.t!10 error instantiating
---
*/
Expand Down

0 comments on commit 4d216e8

Please sign in to comment.