Skip to content

Commit

Permalink
Merge pull request #2464 from 9rnsr/fix9017
Browse files Browse the repository at this point in the history
Issue 9017 - __traits(compiles, { enum e = <expression tuple>; }) is true but code doesn't compile
  • Loading branch information
WalterBright committed Aug 18, 2013
2 parents 7a3dd01 + 435af31 commit 558fffa
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 116 deletions.
3 changes: 3 additions & 0 deletions src/cast.c
Expand Up @@ -1566,6 +1566,9 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)

Expression *TupleExp::castTo(Scope *sc, Type *t)
{
if (type->equals(t))
return this;

TupleExp *e = (TupleExp *)copy();
e->e0 = e0 ? e0->copy() : NULL;
e->exps = (Expressions *)exps->copy();
Expand Down
1 change: 1 addition & 0 deletions src/declaration.c
Expand Up @@ -1126,6 +1126,7 @@ void VarDeclaration::semantic(Scope *sc)
}

VarDeclaration *v = new VarDeclaration(loc, arg->type, id, ti);
v->storage_class |= storage_class;
if (arg->storageClass & STCparameter)
v->storage_class |= arg->storageClass;
//printf("declaring field %s of type %s\n", v->toChars(), v->type->toChars());
Expand Down
12 changes: 12 additions & 0 deletions src/template.c
Expand Up @@ -6438,6 +6438,18 @@ int TemplateInstance::hasNestedArgs(Objects *args)
sa = ((FuncExp *)ea)->fd;
goto Lsa;
}
// Emulate Expression::toMangleBuffer call that had exist in TemplateInstance::genIdent.
if (ea->op != TOKint64 && // IntegerExp
ea->op != TOKfloat64 && // RealExp
ea->op != TOKcomplex80 && // CompexExp
ea->op != TOKnull && // NullExp
ea->op != TOKstring && // StringExp
ea->op != TOKarrayliteral && // ArrayLiteralExp
ea->op != TOKassocarrayliteral && // AssocArrayLiteralExp
ea->op != TOKstructliteral) // StructLiteralExp
{
ea->error("expression %s is not a valid template value argument", ea->toChars());
}
}
else if (sa)
{
Expand Down
19 changes: 16 additions & 3 deletions test/fail_compilation/fail235.d
@@ -1,11 +1,24 @@
/*
Error: expression & D10TypeInfo_a6__initZ is not a valid template value argument
a.d(7): template instance a.Tuple!(& D10TypeInfo_a6__initZ) error instantiating
test_output:
---
fail_compilation/fail235.d(12): Error: expression & _D10TypeInfo_a6__initZ is not a valid template value argument
---
*/
template Tuple(TPL...)
{
alias TPL Tuple;
}

auto K = Tuple!(typeid(char));

/*
test_output:
---
fail_compilation/fail235.d(24): Error: expression & _D10TypeInfo_a6__initZ is not a valid template value argument
---
*/
template Alias(alias A)
{
alias A Alias;
}
auto A = Alias!(typeid(char));

0 comments on commit 558fffa

Please sign in to comment.