www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6538] New: Invalid template constraints crash compiler

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6538

           Summary: Invalid template constraints crash compiler
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-invalid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dsimcha yahoo.com


--- Comment #0 from David Simcha <dsimcha yahoo.com> 2011-08-20 06:57:00 PDT ---
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);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 20 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6538


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-01-10
07:10:24 PST ---
 // 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

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

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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6538



--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2013-01-22 17:23:50 PST ---
 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 22 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6538


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maidenphil hotmail.com


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2013-01-22 19:37:10 PST ---
*** Issue 9361 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6538


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
           Platform|Other                       |All
         OS/Version|Windows                     |All
           Severity|normal                      |major


--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2013-01-22 19:54:33 PST ---
https://github.com/D-Programming-Language/dmd/pull/1539

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6538



--- Comment #5 from github-bugzilla puremagic.com 2013-01-22 21:50:28 PST ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6538


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2013