Bug 2982 – ICE with variadic templates and auto return
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2009-05-15T13:25:00Z
Last change time
2015-06-09T01:18:23Z
Keywords
ice-on-valid-code
Assigned to
bugzilla
Creator
andrei
Comments
Comment #0 by andrei — 2009-05-15T13:25:46Z
This code:
auto max(Ts...)(Ts args)
if (Ts.length >= 2
&& is(typeof(Ts[0].init > Ts[1].init ? Ts[1].init : Ts[0].init)))
{
static if (Ts.length == 2)
return args[1] > args[0] ? args[1] : args[0];
else
return max(max(args[0], args[1]), args[2 .. $]);
}
void main() {
assert(max(4, 5) == 5);
assert(max(2.2, 4.5) == 4.5);
assert(max("Little", "Big") == "Little");
assert(max(4, 5.5) == 5.5);
assert(max(5.5, 4) == 5.5);
}
is greeted with this error:
dmd: inline.c:1423: Expression* FuncDeclaration::doInline(InlineScanState*, Expression*, Array*): Assertion `parameters->dim == arguments->dim' failed.
Aborted
dmd: inline.c:1423: Expression* FuncDeclaration::doInline(InlineScanState*, Expression*, Array*): Assertion `parameters->dim == arguments->dim' failed.
Aborted
when compiled with "-unittest -O -release -inline", and with this error:
dmd: glue.c:939: virtual unsigned int Type::totym(): Assertion `0' failed.
Aborted
when compiled without flags.
Comment #1 by bugzilla — 2009-05-15T22:39:51Z
Reduces to:
auto max(Ts...)(Ts args)
{
return 5;
}
void main() {
assert(max(4, 5) == 5);
}
Comment #2 by gide — 2009-05-16T01:46:18Z
*** Issue 2863 has been marked as a duplicate of this issue. ***
Comment #3 by clugdbug — 2009-05-16T11:57:29Z
Please check if this is the same as 854 (which has an unapplied patch). This is the single most commonly encountered ICE in DMD, it has at least six duplicates.
Comment #4 by dsimcha — 2009-05-16T12:46:56Z
Dup of 2251, which is closely related to and arguably a dup of 854.
*** This issue has been marked as a duplicate of issue 2251 ***