Add note for built-in init property #201

Merged
merged 2 commits into from Dec 9, 2012

Conversation

Projects
None yet
2 participants
Member

9rnsr commented Dec 1, 2012

Built-in .init property sometimes unsafe.

@alexrp alexrp and 1 other commented on an outdated diff Dec 8, 2012

@@ -96,6 +96,47 @@ struct Foo {
Foo.init.a // is 0
Foo.init.b // is 7
----------------
+
+ $(P $(B Note:) $(B .init) produces a default initialized object, not
+ default constructed. That means using $(B .init) is sometimes incorrect.)
+
+ $(OL
+ $(LI If $(B T) is a nested struct, the frame pointer in $(B T.init)
@alexrp

alexrp Dec 8, 2012

Member

Let's use the term context pointer to avoid confusion with the x86 stack terminology?

@9rnsr

9rnsr Dec 9, 2012

Member

OK. Fixed.

@alexrp alexrp and 1 other commented on an outdated diff Dec 8, 2012

+
+----------------
+void main() {
+ int a;
+ struct S {
+ void foo() { a = 1; } // access a variable in enclosing scope
+ }
+ S s1; // OK. S() correctly initialize its frame pointer.
+ S s2 = S(); // OK. same as s1
+ S s3 = S.init; // Bad. the frame pointer in s3 is null
+ s3.foo(); // Access violation
+}
+----------------
+
+ $(LI If $(B T) is a struct which has $(CODE @disable this();), $(B T.init)
+ might return logically incorrect object.)
@alexrp

alexrp Dec 8, 2012

Member

might return a logically incorrect object

@9rnsr

9rnsr Dec 9, 2012

Member

Thanks. Fixed.

@alexrp alexrp added a commit that referenced this pull request Dec 9, 2012

@alexrp alexrp Merge pull request #201 from 9rnsr/note_for_init
Add note for built-in init property
25d4e64

@alexrp alexrp merged commit 25d4e64 into dlang:master Dec 9, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment