DescriptionAllow copying scoped_nsobject of different type.
This code was leading to a crash:
scoped_nsobject<MyClass> a([[MyClass alloc] init]);
scoped_nsobject<NSObject> b(a);
Because |a| is converted to raw pointer, and |b| is constructed with the
raw pointer, without calling retain. This creates a subtle crash later on
when the scoped_nsobject are destroyed.
This code however, was not crashing:
scoped_nsobject<MyClass> b(a);
Because in that case the copy constructor is used.
This was somewhat inconsistent and bug prone, especially if the type of
|a| is changed. In that case the type of |b| must be changed at the same
time, or it causes a crash.
This CL introduces a new constructor for the scoped_nsobject variants
that allows passing a scoped_nsobject of a different type.
It is consistent with scoped_refptr which also has this constructor.
Committed: https://crrev.com/941226ba0e49b1e2d359ea084ecb00c672dd6054
Cr-Commit-Position: refs/heads/master@{#311487}
Patch Set 1 #
Messages
Total messages: 14 (3 generated)
|