Bug 24865 – __traits(hasMember, T, "__xdtor") is true in some cases where there is no __xdtor member

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-11-18T11:30:12Z
Last change time
2024-12-13T19:38:33Z
Assigned to
No Owner
Creator
Jonathan M Davis
Moved to GitHub: dmd#20547 →

Comments

Comment #0 by issues.dlang — 2024-11-18T11:30:12Z
This code --- void main() { import std.stdio; import std.traits; static struct S2 { ~this() { writeln("destroyed"); } } static struct S3 { S2 field; } static struct S6 { S3[0] field; } S6 s6; pragma(msg, "S2: " ~ __traits(allMembers, S2).stringof); pragma(msg, "S2: " ~ __traits(hasMember, S2, "__xdtor").stringof); pragma(msg, "S3: " ~ __traits(allMembers, S3).stringof); pragma(msg, "S3: " ~ __traits(hasMember, S3, "__xdtor").stringof); pragma(msg, "S6: " ~ __traits(allMembers, S6).stringof); pragma(msg, "S6: " ~ __traits(hasMember, S6, "__xdtor").stringof); } --- prints out --- S2: AliasSeq!("__dtor", "__xdtor", "opAssign") S2: true S3: AliasSeq!("field", "__xdtor", "opAssign") S3: true S6: AliasSeq!("field", "opAssign") S6: true --- when compiling, and it prints out nothing when it runs. S6 should not have a destructor, because while the elements of its static array have destructors, the static array has no length, and so, there's nothing to destroy. The fact that nothing prints out when running the program shows that S6 has no destructor. allMembers also has no __xdtor member, which lines up with the behavior of the running program. However, for some reason, hasMember reports that there _is_ an __xdtor member. Given that allMembers matches the actual behavior, I'm inclined to think that the bug is in hasMember rather than there being an invisible __xdtor that allMembers isn't reporting, but either way, there is a discrepancy here which needs to be fixed. This affects the implementation of {core.internal,std}.traits.hasElaborateDestructor.
Comment #1 by robert.schadek — 2024-12-13T19:38:33Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20547 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB