Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 9017 - __traits(compiles, { enum e = <expression tuple>; }) is true but code doesn't compile #2464

Merged
merged 3 commits into from Aug 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -6439,6 +6439,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));