Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
May 26, 2010 [Issue 4237] New: Link error with typedefs of the same name in a function scope | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=4237 Summary: Link error with typedefs of the same name in a function scope Product: D Version: 2.041 Platform: x86 OS/Version: All Status: NEW Keywords: link-failure Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: rsinfu@gmail.com --- Comment #0 from Shin Fujishiro <rsinfu@gmail.com> 2010-05-26 12:35:19 PDT --- Typedefs in function scope don't get fully mangled with scope information. As a result, the following code won't link: -------------------- test.d struct Struct(T) { T value; } void main() { { typedef int Number = 1; Struct!Number s; pragma(msg, "1: ", typeof(s).mangleof); } { typedef real Number = 2; Struct!Number s; pragma(msg, "2: ", typeof(s).mangleof); } } -------------------- On Linux and FreeBSD: -------------------- 1: S4test20__T6StructTT6NumberZ6Struct 2: S4test20__T6StructTT6NumberZ6Struct test.o(.rodata+0x18): multiple definition of `_Dmain6Number6__initZ' test.o(.rodata+0x14): first defined here -------------------- On Windows: -------------------- 1: S4test20__T6StructTT6NumberZ6Struct 2: S4test20__T6StructTT6NumberZ6Struct OPTLINK (R) for Win32 Release 8.00.2 Copyright (C) Digital Mars 1989-2009 All rights reserved. http://www.digitalmars.com/ctg/optlink.html test.obj(test) Offset 0027DH Record Type 0091 Error 1: Previous Definition Different : _Dmain6Number6__initZ --- errorlevel 1 -------------------- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 28, 2010 [Issue 4237] Typedefs of the same name cause initializer conflict | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shin Fujishiro | http://d.puremagic.com/issues/show_bug.cgi?id=4237 Shin Fujishiro <rsinfu@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch Summary|Link error with typedefs of |Typedefs of the same name |the same name in a function |cause initializer conflict |scope | --- Comment #1 from Shin Fujishiro <rsinfu@gmail.com> 2010-05-28 04:51:17 PDT --- Maybe the example in #0 should be error. I filed a separate bug 4245. Still the problem exists. As shown in the output example below, the two distinct typedefs get mangled to the same name. Then the assertion fails due to the corrupted initial value. -------------------- test.d struct Struct(T) { T value; } void foo() { typedef int Number = 1; Struct!Number s; pragma(msg, typeof(s).mangleof); assert(s.value == 1); } void bar() { typedef real Number = 2; Struct!Number s; pragma(msg, typeof(s).mangleof); assert(s.value == 2); // Assertion failure } void main() { foo(); bar(); } -------------------- % dmd -run test S4test20__T6StructTT6NumberZ6Struct S4test20__T6StructTT6NumberZ6Struct core.exception.AssertError@test(14): Assertion failure -------------------- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 28, 2010 [Issue 4237] Typedefs of the same name cause initializer conflict | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shin Fujishiro | http://d.puremagic.com/issues/show_bug.cgi?id=4237 --- Comment #2 from Shin Fujishiro <rsinfu@gmail.com> 2010-05-28 04:54:49 PDT --- Here's a trivial patch to dmd svn r502. --- src/declaration.c +++ src/declaration.c @@ -296,6 +296,7 @@ Dsymbol *TypedefDeclaration::syntaxCopy(Dsymbol *s) void TypedefDeclaration::semantic(Scope *sc) { //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem); + parent = sc->parent; if (sem == 0) { sem = 1; basetype = basetype->semantic(loc, sc); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 28, 2010 [Issue 4237] Typedefs of the same name cause initializer conflict | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shin Fujishiro | http://d.puremagic.com/issues/show_bug.cgi?id=4237 --- Comment #3 from Shin Fujishiro <rsinfu@gmail.com> 2010-05-28 06:02:42 PDT --- The comment #2 patch set ->parent everytime = wrong. This one is better: --- src/declaration.c +++ src/declaration.c @@ -298,6 +298,7 @@ void TypedefDeclaration::semantic(Scope *sc) //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem); if (sem == 0) { sem = 1; + parent = sc->parent; basetype = basetype->semantic(loc, sc); sem = 2; #if DMDV2 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 11, 2011 [Issue 4237] Typedefs of the same name cause initializer conflict | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shin Fujishiro | http://d.puremagic.com/issues/show_bug.cgi?id=4237 --- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2011-10-10 19:35:56 PDT --- (In reply to comment #3) > The comment #2 patch set ->parent everytime = wrong. This one is better: > > --- src/declaration.c > +++ src/declaration.c > @@ -298,6 +298,7 @@ void TypedefDeclaration::semantic(Scope *sc) > //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem); > if (sem == 0) > { sem = 1; > + parent = sc->parent; > basetype = basetype->semantic(loc, sc); > sem = 2; > #if DMDV2 Pushed as pull request: https://github.com/D-Programming-Language/dmd/pull/445 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 11, 2011 [Issue 4237] Typedefs of the same name cause initializer conflict | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shin Fujishiro | http://d.puremagic.com/issues/show_bug.cgi?id=4237 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla@digitalmars.com Resolution| |FIXED --- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2011-10-11 15:01:46 PDT --- https://github.com/D-Programming-Language/dmd/commit/1cc61cbccf64c65c3257326a1df02519c06808c1 https://github.com/D-Programming-Language/dmd/commit/a6586474a8cc7ae92f13afabfeffcaa5ac085d1d -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation