Skip to content

Commit

Permalink
Merge pull request #2201 from rainers/fix_6461
Browse files Browse the repository at this point in the history
Fix 6461 - multiple definitions with typeid and multiobj
  • Loading branch information
WalterBright committed Jun 27, 2013
2 parents 42d92fa + 8cf0a95 commit 482a6fd
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,33 @@ void obj_write_deferred(Library *library)
OutBuffer idbuf;
idbuf.printf("%s.%d", m ? m->ident->toChars() : mname, count);
char *idstr = idbuf.toChars();
idbuf.data = NULL;
Identifier *id = new Identifier(idstr, TOKidentifier);

Module *md = new Module(mname, id, 0, 0);
md->members = new Dsymbols();
md->members->push(s); // its only 'member' is s
if (m)
if(!m)
{
// it doesn't make sense to make up a module if we don't know where to put the symbol
// so output it into it's own object file without ModuleInfo
objmod->initfile(idstr, NULL, mname);
s->toObjFile(0);
objmod->termfile();
}
else
{
idbuf.data = NULL;
Identifier *id = new Identifier(idstr, TOKidentifier);

Module *md = new Module(mname, id, 0, 0);
md->members = new Dsymbols();
md->members->push(s); // its only 'member' is s
md->doppelganger = 1; // identify this module as doppelganger
md->md = m->md;
md->aimports.push(m); // it only 'imports' m
md->massert = m->massert;
md->munittest = m->munittest;
md->marray = m->marray;
}

md->genobjfile(0);

md->genobjfile(0);
}

/* Set object file name to be source name with sequence number,
* as mangled symbol names get way too long.
*/
Expand Down
4 changes: 4 additions & 0 deletions test/compilable/extra-files/test6461/a.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module a;
import tmpl;
TypeInfo fun() { return typeid(Tmpl!int()); }

4 changes: 4 additions & 0 deletions test/compilable/extra-files/test6461/b.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module b;
import tmpl;
TypeInfo fun() { return typeid(Tmpl!long()); }

6 changes: 6 additions & 0 deletions test/compilable/extra-files/test6461/main.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import a, b;
void main() {
auto t1 = a.fun();
auto t2 = b.fun();
assert(t1 != t2);
}
4 changes: 4 additions & 0 deletions test/compilable/extra-files/test6461/tmpl.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module tmpl;
struct Tmpl(T) {
T a;
}
21 changes: 21 additions & 0 deletions test/compilable/test6461.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

name=`basename $0 .sh`
dir=${RESULTS_DIR}/compilable
src=compilable/extra-files/test6461

if [ "${OS}" == "win32" -o "${OS}" == "win64" ]; then
LIBEXT=.lib
else
LIBEXT=.a
fi

$DMD -lib -m${MODEL} -of${dir}/a${LIBEXT} -I${src} ${src}/a.d || exit 1
$DMD -lib -m${MODEL} -of${dir}/b${LIBEXT} -I${src} ${src}/b.d || exit 1

$DMD -m${MODEL} -od${dir} -I${src} ${src}/main.d ${dir}/a${LIBEXT} ${dir}/b${LIBEXT} || exit 1

rm -f ${dir}/{a${LIBEXT} b${LIBEXT} main${EXE} main${OBJ}}

echo Success >${dir}/test6461.sh.out

0 comments on commit 482a6fd

Please sign in to comment.