Bug 4366 – ICE(mtype.c) constrained template pure function with array/pointer parameter
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-06-22T04:56:00Z
Last change time
2014-02-15T02:44:01Z
Keywords
ice-on-valid-code
Assigned to
nobody
Creator
rsinfu
Comments
Comment #0 by rsinfu — 2010-06-22T04:56:04Z
DMD aborts with assertion failure in Type::check() if a constrained templated pure function has a named parameter of array or pointer type.
Compiling the following causes dmd to abort (2.045 and r556):
--------------------
void foo(T)(T a, T[] b) pure if (1)
{
}
alias foo!(int) K;
--------------------
% dmd -o- -c test
Assertion failed: (tn->mod & MODimmutable || tn->mod & MODconst), function check, file mtype.c, line 871.
--------------------
GDB backtrace:
...
#3 0x283a2ef6 in __assert () from /lib/libc.so.7
#4 0x080fa0fe in Type::check ()
#5 0x080fa23f in Type::fixTo ()
#6 0x081001b7 in Type::constOf ()
#7 0x08136150 in TemplateDeclaration::makeParamNamesVisibleInConstraint ()
#8 0x08136415 in TemplateDeclaration::matchWithInstance ()
#9 0x08138cac in TemplateInstance::findBestMatch ()
#10 0x08139c67 in TemplateInstance::semantic ()
#11 0x0813a190 in TemplateInstance::semantic ()
#12 0x081005d3 in TypeInstance::resolve ()
...
The assertion does not fail in the following cases:
--------------------
void bar(T)(T a, T[] b) pure { } // no constraint
void dee(T)(T a, T[] ) pure if (1) { } // array parameter is unnamed
void mew(T)(T a, T[] b) if (1) { } // impure
alias bar!(int) L; // okay
alias dee!(int) M; // okay
alias mew!(int) N; // okay
--------------------
Comment #1 by clugdbug — 2010-06-24T00:29:57Z
The ICE occurs during the call in these lines in template.c, makeParamNamesVisibleInConstraint().
if (fd->type && fd->isPure())
vtype = vtype->addMod(MODconst);
Removing those lines allows the code to compile, and the DMD test suite still passes. So why are they there? I wrote the makeParamNamesVisibleInConstraint() function, but I just copied those lines from func.c, where interestingly they don't cause any problems. Still need to work out what the difference is.
Comment #2 by bugzilla — 2010-11-07T12:25:27Z
*** This issue has been marked as a duplicate of issue 4434 ***