www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4328] New: templated unittests fail to link when instantiated from other file if compiler order isn't correct

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4328

           Summary: templated unittests fail to link when instantiated
                    from other file if compiler order isn't correct
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: schveiguy yahoo.com



06:46:44 PDT ---
testunittest.d:

struct S(T)
{
  unittest
  {
    assert(0);
  }
}

testunittestmain.d:

import testunittest;
void main()
{
    S!int s;
}

When compiled this way:

dmd -unittest testunittest.d testunittestmain.d

The following error occurs:
testunittest.o: In function `_D12testunittest8__T1STiZ1S11__unittest3FZv':
testunittestmain.d:(.text._D12testunittest8__T1STiZ1S11__unittest3FZv+0x9):
undefined reference to `_D12testunittest15__unittest_failFiZv'
collect2: ld returned 1 exit status

If I compile this way:

dmd -unittest testunittestmain.d testunittest.d


The compiler generally has no problem with order of files for linking, I would
expect the same here.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 16 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4328


Rainer Schuetze <r.sagitario gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario gmx.de



PDT ---
even worse: the link fails if the template is in a library and the library is
not compiled with unittests:

import std.stdio;

void main()
{
    writef("\n");
}

dmd -unittest test.d

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)
 Error 42: Symbol Undefined _D3std6format15__unittest_failFiZv
--- errorlevel 1

Strangely, the relased phobos.lib is compiled with unittests, while the
makefile does not pass "-unittest". So this does only show up when I compile
the runtime library myself.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 27 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4328




PDT ---
Here's a workaround: similar to the assert handling, generate the unittest_fail
function whenever there is a template in the module:

Index: template.c
===================================================================
--- template.c    (revision 632)
+++ template.c    (working copy)
   -429,6 +429,13   
         sc->module->toModuleAssert();
     }

+    if (/*global.params.useUnitTests &&*/ sc->module)
+    {
+        // Generate this function as it may be used
+        // when template is instantiated in other modules
+        sc->module->toModuleUnittest();
+    }
+
     /* Remember Scope for later instantiations, but make
      * a copy since attributes can change.
      */

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 27 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4328


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



23:52:53 PST ---
https://github.com/D-Programming-Language/dmd/commit/76038f0813c514c2690d4e01ea7ff3aed0434ea4

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 06 2011