Bug 6538 – ICE(mangle.c) Invalid template constraints

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-08-20T06:57:00Z
Last change time
2014-01-24T22:22:45Z
Keywords
ice, pull
Assigned to
nobody
Creator
dsimcha

Comments

Comment #0 by dsimcha — 2011-08-20T06:57:00Z
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. ***
Comment #4 by k.hara.pg — 2013-01-22T19:54:33Z
Comment #5 by github-bugzilla — 2013-01-22T21:50:28Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/b950009c4a24f34e9dda4a52092f633cff59f940 fix Issue 6538 - ICE(mangle.c) Invalid template constraints https://github.com/D-Programming-Language/dmd/commit/f795e1b816e6a1dcc5667aecad0e1f937a3ddb12 Merge pull request #1539 from 9rnsr/fix6538 Issue 6538 - ICE(mangle.c) Invalid template constraints
Comment #6 by github-bugzilla — 2014-01-23T23:22:14Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f6d861b2bb083812f24b43d2d50c70222626b039 [Improve] Relax restrictions on issue 6538 and 9361 Now pseudo symbols are placed in emulated scopes, and taking them by alias parameter is allowed.
Comment #7 by github-bugzilla — 2014-01-24T22:22:45Z
Commit pushed to 2.065 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/d88598d4168a16fac1afea6e7d4cb22be707d487 Revert "[Improve] Relax restrictions on issue 6538 and 9361" This reverts commit f6d861b2bb083812f24b43d2d50c70222626b039.