The following code crashes the compiler on Windows:
template allSatisfy(alias F, T...)
{
enum bool allSatisfy = true;
}
template isIntegral(T)
{
enum bool isIntegral = true;
}
// This is invalid because allSatisfy is passed sizes, not I.
void foo(I...)(I sizes)
if(allSatisfy!(isIntegral, sizes)) {}
void main() {
auto arr = foo(42, 86);
}
Comment #1 by andrej.mitrovich — 2013-01-10T07:10:24Z
> // This is invalid because allSatisfy is passed sizes, not I.
I don't think this is invalid because T... accepts aliases. It's not what the user wants, but it's valid code, e.g.:
template isIntegral(T)
{
enum bool isIntegral = true;
}
template allSatisfy(alias z, F...)
{
enum bool allSatisfy = true;
}
void foo(T)(T x, T y)
if (allSatisfy!(isIntegral, x, y)) // compiles fine
{ }
void main()
{
foo(1, 2);
}
The stacktrace for OP sample:
0012e340 004a86f7 DMD!halt+0x5(...)
0012e394 004a85d7 DMD!mangle+0x163
0012e3ec 004a87e9 DMD!mangle+0x43
0012e434 0044fa3b DMD!Declaration::mangle()+0xce(...)
0012e4a0 0044e08d DMD!TemplateInstance::genIdent(ArrayBase<Object >*)+0x2c0
0012e5a8 0044d93a DMD!TemplateInstance::semantic(Scope*,ArrayBase<Expression >*)+0x4d5
0012e5bc 0042995d DMD!TemplateInstance::semantic(Scope*)+0x14
0012e620 0044791c DMD!ScopeExp::semantic(Scope*)+0x4a
0012e9b4 004483d1 DMD!+0x1ee6
0012eb84 004339d6 DMD!TemplateDeclaration::deduceFunctionTemplate(Scope*,Loc,ArrayBase<Object >*,Expression*,ArrayBase<Expression >*,int )+0x426
0012f050 004809fa DMD!CallExp::semantic(Scope*)+0x1e18
0012f068 004811de DMD!ExpStatement::semantic(Scope*)+0x24
0012f25c 004695b9 DMD!CompoundStatement::semantic(Scope*)+0xe5
0012fb00 0049b523 DMD!FuncDeclaration::semantic3(Scope*)+0x1430
0012fb30 00404d29 DMD!Module::semantic3()+0xc3(...)
0012ff44 0040546b DMD!tryMain+0x281a
0012ff80 00565111 DMD!main+0x43
0012ffc0 7c817067 DMD!mainCRTStartup+0xa9
0012fff0 00000000 0x7c817067
It's some kind of mangling issue.
Comment #2 by k.hara.pg — 2013-01-22T17:23:50Z
> void foo(I...)(I sizes)
> if (allSatisfy!(isIntegral, sizes)) {}
In this case, allSatisfy is instantiated with the symbol 'sizes', but it does not have an actual entity so foo is not yet instantiated. When a template is instantiated, its symbol arguments must have valid mangled names, but in this case, 'sizes' cannot have that. So this is an ice-on-invalid bug.
And also, bug 9361 is a special case of this bug.
struct Unit(A)
{
void butPleaseDontUseMe()()
if (is(unitType!((this)))) // !
{}
}
template isUnit(alias T) if ( is(T)) {}
template isUnit(alias T) if (!is(T)) {}
template unitType(alias T) if (isUnit!T) {}
void main()
{
Unit!int u;
u.butPleaseDontUseMe(); // crashes
}
In the template constraint for the member function template, 'this' expression is also a *pseudo* symbol as same as the function parameters. So, taking them through alias template parameter should be rejected.
Comment #3 by k.hara.pg — 2013-01-22T19:37:10Z
*** Issue 9361 has been marked as a duplicate of this issue. ***