The current default implementation for template RTInfo always sets the value 0x12345678, so this should work:
////////////////
module s;
struct S
{
int x;
void* p;
}
///////////////
module test;
import s;
struct T
{
int x;
void* p;
}
void main()
{
assert(typeid(T).rtInfo == cast(void*)0x12345678); // ok
assert(typeid(S).rtInfo == cast(void*)0x12345678); // fails
}
////////////////
but the second assertion triggers if compiled with
dmd test.d
If you add s.d to the command line, it does not fail.
Comment #1 by r.sagitario — 2013-06-22T01:39:46Z
This is not restricted to the typeid expression, but also happens for other operations like array appending. I suspect it happens if it is only the backend that is requesting the type info, and then, AggregateDeclaration::semantic3 is never run.
(In reply to Rainer Schuetze from comment #0)
> The current default implementation for template RTInfo always sets the value
> 0x12345678, so this should work:
>
> ////////////////
> module s;
>
> struct S
> {
> int x;
> void* p;
> }
>
> ///////////////
> module test;
>
> import s;
>
> struct T
> {
> int x;
> void* p;
> }
>
> void main()
> {
> assert(typeid(T).rtInfo == cast(void*)0x12345678); // ok
> assert(typeid(S).rtInfo == cast(void*)0x12345678); // fails
> }
>
> ////////////////
> but the second assertion triggers if compiled with
>
> dmd test.d
I think the typeid(S) object should not be generated when s.d is not directly compiled. IOW, `dmd test.d` should cause link failure.
I implemented the behavior in:
https://github.com/D-Programming-Language/dmd/pull/3958
Comment #4 by r.sagitario — 2017-12-24T09:11:11Z
still happens in dmd 2.077
Comment #5 by slavo5150 — 2018-01-30T02:34:14Z
The following example results in an assertion failure:
struct T
{
int x;
void* p;
}
void main()
{
assert(typeid(T).rtInfo == cast(void*)0x12345678); // Fail
}
However, the following passes:
struct T
{
int x;
void* p;
}
void main()
{
assert(typeid(T).rtInfo is null);
}
This is consistent with what I see in the runtime: https://github.com/dlang/druntime/blob/544946df1c68727d84cdee11502b244bde0bc22e/src/object.d#L3419
So, I don't understand what the problem is and what the result should be.
@rainers updated dlang/dmd pull request #2480 "fix issues #10442: no or incomplete RTInfo" fixing this issue:
- fix issue 10442: predict type info references in glue layer
- add test case for issue 10442
https://github.com/dlang/dmd/pull/2480
Comment #8 by robert.schadek — 2024-12-13T18:08:28Z