Bug 23113 – Bug in CTFE initialization of redBlackTree?

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2022-05-16T12:42:04Z
Last change time
2024-12-13T19:22:47Z
Keywords
CTFE
Assigned to
No Owner
Creator
Daniel Čejchan
Moved to GitHub: dmd#20103 →

Comments

Comment #0 by czdanol — 2022-05-16T12:42:04Z
```D import std.container.rbtree; import std.stdio; const baseTypes = redBlackTree( "Float", "Float2", "Float3", "Bool", "Block", "Rule", "ComponentNode" ); void main() { foreach(string s; baseTypes) writeln(s); } ``` Running this code throws: ``` core.exception.AssertError@/dlang/dmd/linux/bin64/../../src/phobos/std/container/rbtree.d(264): parent must not be null ```
Comment #1 by duser — 2022-05-24T06:36:36Z
reduced the example to this: void main() { { Tree tree = Tree(1); assert(tree.node is tree.node.self); // ok } { __gshared static Tree tree = Tree(1); assert(tree.node is tree.node.self); // fail } } struct Tree { Node* node; this(int) { node = new Node; node.set(); assert(node.self is node); // ok } } struct Node { Node* self; void set() { self = &this; } } "&this" inside a struct in CTFE seems to have a wrong value when converted to static data (it's correct if you check it with assert in CTFE but not if you check the value at runtime)
Comment #2 by robert.schadek — 2024-12-13T19:22:47Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20103 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB