[Issue 18833] New: [REG 2.073] DMD in some cases forgets to generate wrapping TypeInfo for modifiers on classes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun May 6 13:08:59 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18833

          Issue ID: 18833
           Summary: [REG 2.073] DMD in some cases forgets to generate
                    wrapping TypeInfo for modifiers on classes
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: link-failure, rejects-valid
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: schveiguy at yahoo.com

Given an imported non-root module (e.g. one from a library), that instantiates
a template class inside an auto function that is NOT a template, if you try to
access a modified typeinfo for that object, it will fail to generate the
wrapping TypeInfo.

For example a const(MyObject!params).

Simplest example:

mod1.d:
module mod1;

class C(T)
{
}

auto foo()
{
    return new C!int;
}

app.d:
import mod1;

void main()
{
    const s = foo();
    alias T = typeof(s);
    auto x = typeid(T);
}

Compile like this:

dmd -c mod1.d
dmd app.d mod1.o
Error:
Undefined symbols for architecture x86_64:
  "__D26TypeInfo_xC4mod1__T1CTiZQf6__initZ", referenced from:
      __Dmain in app.o
ld: symbol(s) not found for architecture x86_64

The missing TypeInfo is for const(C!int)

What I think happens is that in order to compile, it has to semantic the foo
function, which means it sees that mod1 has already instantiated the C!int
template. This is a situation pretty much reserved for auto functions. It
requires a template instantiation in a non-root module, that is NOT inside
another template. See typinf.d's function isSpeculativeType, where it checks a
typeinfo's minst. That minst is set to null inside
dsymbolsem.templateInstanceSemantic with this code:

    // https://issues.dlang.org/show_bug.cgi?id=10920
    // If the enclosing function is non-root symbol,
    // this instance should be speculative.
    if (!tempinst.tinst && sc.func && sc.func.inNonRoot())
    {
        tempinst.minst = null;
    }

So I don't know how to fix. You don't want to re-instantiate the template, but
you still need the wrapping typeinfo. The compiler seems to ignore the type
modifier when checking to see if it should emit the typeinfo.

--


More information about the Digitalmars-d-bugs mailing list