digitalmars.D.bugs - [Issue 2206] New: unnamed template mixin of class inside function or class has incorrect classinfo and mangleof
- d-bugmail puremagic.com (38/38) Jul 08 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2206
- d-bugmail puremagic.com (19/19) Jul 08 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2206
- d-bugmail puremagic.com (36/36) Jul 09 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2206
- d-bugmail puremagic.com (11/11) Dec 04 2010 http://d.puremagic.com/issues/show_bug.cgi?id=2206
http://d.puremagic.com/issues/show_bug.cgi?id=2206
Summary: unnamed template mixin of class inside function or class
has incorrect classinfo and mangleof
Product: D
Version: 1.029
Platform: PC
OS/Version: Linux
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla digitalmars.com
ReportedBy: kamm-removethis incasoftware.de
Test:
--
template T() {
class C {}
}
void main()
{
mixin T!(); // using a named mixin here fixes it
pragma(msg, T!().C.mangleof);
pragma(msg, C.mangleof); // incorrectly outputs the same as above
assert(T!().C.classinfo !is C.classinfo); // fails
assert(T!().C.mangleof != C.mangleof); // fails
}
--
The types of T!().C and main.C are clearly different as the nested one carries
an additional context pointer. This means that allocation relying on
classinfo.init.length should be wrong too.
In the frontend the types are initially different and only merged into a single
type during semantic. To be specific, Type::mangle unifies them as toDecoBuffer
yields the same result for both.
Maybe this could be fixed by adding a TemplateMixin::mangle overload. This
frontend bug causes some template-mixin related bugs in LLVMDC that seem to be
worked around somehow in DMD.
--
Jul 08 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2206
-------
To illustrate the resulting problem with class allocation:
--
import std.stdio;
class D {}
template T() {
class C { this() { } }
}
void main()
{
mixin T!();
// all print 8
writefln(T!().C.classinfo.init.length);
writefln(C.classinfo.init.length);
writefln(D.classinfo.init.length);
auto c = new C; // segfault in _d_newclass
}
--
Jul 08 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2206
kamm-removethis incasoftware.de changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
-------
Adding the following override for TemplateMixin::mangle seems to have fixed the
issue in LLVMDC:
--
char *TemplateMixin::mangle()
{
OutBuffer buf;
char *id;
#if 0
printf("TemplateMixin::mangle() %s", toChars());
if (parent)
printf(" parent = %s %s", parent->kind(), parent->toChars());
printf("\n");
#endif
id = ident ? ident->toChars() : toChars();
// use parent instead of tempdecl->parent here
if (parent)
{
char *p = parent->mangle();
if (p[0] == '_' && p[1] == 'D')
p += 2;
buf.writestring(p);
}
buf.printf("%"PRIuSIZE"%s", strlen(id), id);
id = buf.toChars();
buf.data = NULL;
//printf("TemplateMixin::mangle() %s = %s\n", toChars(), id);
return id;
}
--
--
Jul 09 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2206
Walter Bright <bugzilla digitalmars.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
21:23:55 PST ---
http://www.dsource.org/projects/dmd/changeset/777
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 04 2010









d-bugmail puremagic.com 