www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18338] New: typeid expression causes typeInfo to be duplicated

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

          Issue ID: 18338
           Summary: typeid expression causes typeInfo to be duplicated
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: code benjamin-thaut.de

Created attachment 1678
  --> https://issues.dlang.org/attachment.cgi?id=1678&action=edit
Repro case

In the attached repro case, when compiling test.d via:
dmd -m64 test.d -c

The TypeInfo for file.DirEntry ( _D24TypeInfo_S4file8DirEntry6__initZ) will be
emitted into the object file even though its never used in test.d

This is a problem when file.d is build into a dll. Because this results in a
duplication of the type info. As a result cross dll casts and throws and all
other type info related operations may fail.

The cause is the typeid expression in file.d. As soon as the compiler
encounters a typeid expression it will instanciate the typeinfo for this type
even if the typeid expression is in a non root module. Typeid expressions
should only instanciate the type info if the typeid expression is part of a
root module.

--
Jan 30 2018