2229 – ICE(template.c) instantiating an invalid variadic template with more than one argument

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2229 - ICE(template.c) instantiating an invalid variadic template with more than one argument
Summary: ICE(template.c) instantiating an invalid variadic template with more than one...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: diagnostic, ice-on-invalid-code, patch
: 2230 2435 2555 2566 3482 (view as issue list)
Depends on:
Blocks:
Reported: 2008年07月16日 03:56 UTC by Max Samukha
Modified: 2014年03月01日 00:37 UTC (History)
5 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2008年07月16日 03:56:41 UTC
T foo(A...)()
{
 return "";
}
void main()
{
 foo!(1, 2)(); // crashes when there is more than one parameter
}
Comment 1 Stewart Gordon 2008年07月16日 05:25:20 UTC
Please remember to assign keywords to bug reports. To everybody reading this: Please look through issues you've reported and check for missing keywords.
Also, please avoid vague summary lines that could equally apply to many unrelated bugs. As a guide, if there exists a keyword that says what your summary says, then the summary is too vague.
Comment 2 Max Samukha 2008年07月16日 06:30:40 UTC
Ok. Could the bugzilla ugliness be modified so that there is a combo from which to select keywords? I keep forgetting their spelling.
I have changed the summary because the compiler crashes when the template is parametrized with any tuple containing more than one element.
Comment 3 Max Samukha 2008年07月16日 06:32:18 UTC
*** Bug 2230 has been marked as a duplicate of this bug. ***
Comment 4 Stewart Gordon 2008年07月17日 11:58:32 UTC
(In reply to comment #2)
> Ok. Could the bugzilla ugliness be modified so that there is a combo from which
> to select keywords? I keep forgetting their spelling.
Really, a <select multiple> is what we want. I don't know whether there's an option in Bugzilla to do this, but it could probably be done by hacking the local installation. That said, the version of Bugzilla we're using here is far from current, so FAIK the best COA might be to upgrade.
Comment 5 David Simcha 2009年01月09日 14:20:24 UTC
*** Bug 2435 has been marked as a duplicate of this bug. ***
Comment 6 Don 2009年01月14日 00:50:53 UTC
Again, I note that this applies to D1.x as well
Test case from the closed bug 2345.
---
Foo foo(A...)()
{
}
static assert(foo!(1, 2)());
Comment 7 Don 2009年04月03日 07:11:56 UTC
*** Bug 2566 has been marked as a duplicate of this bug. ***
Comment 8 Don 2009年04月03日 07:15:51 UTC
No longer segfaults.
---------
DMD 1.042:
Assertion failure: 'i < parameters->dim' on line 806 in file 'template.c'
abnormal program termination
-------
DMD2.027:
bug.d(1): Error: template fog.foo(A...) declaration A is already defined
which seems incorrect.
Comment 9 Don 2009年04月03日 08:13:23 UTC
*** Bug 2555 has been marked as a duplicate of this bug. ***
Comment 10 Don 2009年09月12日 11:50:02 UTC
This is actually really simple. 
ROOT CAUSE: The D1 logic in template.c, TemplateDeclaration::deduceFunctionTemplateMatch() is completely wrong.
if (nargsi > parameters->dim) && tp, the assert in the for loop will definitely fail.
PATCH (around line 797 of template.c):
==========
 if (targsi)
 {	// Set initial template arguments
	nargsi = targsi->dim;
+	size_t argsToUse = nargsi;
	if (nargsi > parameters->dim)
	{ if (!tp)
		goto Lnomatch;
	 dedargs->setDim(nargsi);
	 dedargs->zero();
+	 argsToUse = parameters->dim;
	}
	memcpy(dedargs->data, targsi->data, nargsi * sizeof(*dedargs->data));
-	for (size_t i = 0; i < nargsi; i++)
+	for (size_t i = 0; i < argsToUse; i++)
	{ assert(i < parameters->dim);
This patch also fixes bug 1897.
Comment 11 Walter Bright 2009年10月13日 13:51:09 UTC
Fixed dmd 1.049
Comment 12 Don 2009年11月07日 14:51:08 UTC
The patch for this bug was incorrectly transcribed.
template.c, line 807.
-	memcpy(dedargs->data, targsi->data, n * sizeof(*dedargs->data));
+	memcpy(dedargs->data, targsi->data, nargsi * sizeof(*dedargs->data));
This is causing dstress case for bug 1144 to fail.
http://dstress.kuehne.cn/nocmpile/m/mixin_34_A.d 
Comment 13 Don 2009年11月07日 22:43:31 UTC
*** Issue 3482 has been marked as a duplicate of this issue. ***
Comment 14 Walter Bright 2009年12月06日 00:49:17 UTC
Fixed dmd 1.053


AltStyle によって変換されたページ (->オリジナル) /