Skip to content

Commit

Permalink
Merge pull request #2977 from 9rnsr/fix11756
Browse files Browse the repository at this point in the history
Issue 11756 - Irrelevant variable name printing in CTFE error message
  • Loading branch information
AndrejMitrovic committed Dec 17, 2013
2 parents 53755c0 + e9d52b7 commit 83728b9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ctfeexpr.c
Expand Up @@ -2276,7 +2276,7 @@ Expression *TypeStruct::voidInitLiteral(VarDeclaration *var)
exps->setDim(sym->fields.dim);
for (size_t i = 0; i < sym->fields.dim; i++)
{
(*exps)[i] = sym->fields[i]->type->voidInitLiteral(var);
(*exps)[i] = sym->fields[i]->type->voidInitLiteral(sym->fields[i]);
}
StructLiteralExp *se = new StructLiteralExp(var->loc, sym, exps);
se->type = this;
Expand Down
39 changes: 39 additions & 0 deletions test/fail_compilation/diag11756.d
@@ -0,0 +1,39 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag11756.d(15): Error: cannot read uninitialized variable cnt in CTFE
fail_compilation/diag11756.d(34): called from here: foo.ptr2.opAssign(Ptr(& n))
fail_compilation/diag11756.d(39): called from here: test()
fail_compilation/diag11756.d(39): while evaluating: static assert(test())
---
*/

struct Ptr
{
void opAssign(Ptr other)
{
(*cnt)--; // error
cnt = other.cnt;
(*cnt)++;
}
size_t *cnt;
}

union Foo
{
size_t *ptr1;
Ptr ptr2;
}

bool test()
{
Foo foo;
size_t cnt = 1;
foo.ptr1 = &cnt;
size_t n;
foo.ptr2 = Ptr(&n);
assert(cnt == 0);

return true;
}
static assert(test());

0 comments on commit 83728b9

Please sign in to comment.